Cannot convert value of parameter 'Course_FK' from 'System.String' to 'System.Guid'


I'm building a site and I've been trying to accomplish something similar to what is talked about in "Working with Data in ASP.NET 2.0 :: Declarative Parameters" tutorial.

Below is the code for my methods from the xsd. I tried to attach a screenshot of my xsd but for some reason I'm not allowedSad


SELECT        CourseID, Name
FROM            Course


SELECT        ScheduleID, Course_FK, Date, TeeTime, NumberOfPlayers
FROM            Schedule
WHERE        (Course_FK = @Course_FK)

The problem is that when I run my site I get the error that I mentioned in the subject line. My approach to my problem is the same as in the tutorial that I'm using. I'm obviously doing something wrong but I can't see the difference between my SELECT's and the one in the tutorial. For some reason when I use @Course_FK the datatype is GUID?

I've tried conveting/casting to different typs but the compiler keeps telling me I cannot convert from GUID to whatever I'm trying to convert to.


8/19/2006 6:41:09 PM 16182 articles. 0 followers. Follow

9 Replies

Similar Articles

[PageSpeed] 40
Get it on Google Play
Get it on Apple App Store

Hi~ To me "Cannot convert value of parameter 'Course_FK' from 'System.String' to 'System.Guid' " means the parameter is string but the one your method needed is guid~ You may check your .xsd to see if the filed was set in the right type~
你好! Just FYI o_O
8/21/2006 8:12:17 AM

Although the compiler nor the runtime complain, I am getting no results for this inside my gridview. I've double checked that the right value is being passed because I had it print to a lable i.e. courseID

Here is the code behind:

protected void SearchButton_Click(object sender, EventArgs e)
        Label2.Text = (CourseDropDownList.SelectedValue.ToString());
        Guid courseID = new Guid(CourseDropDownList.SelectedValue.ToString());
        ScheduleTableAdapter scheduleAdapter = new ScheduleTableAdapter();
        CourseScheduleGridView.DataSource = scheduleAdapter.GetCourseScheduleByCourseID(courseID);

 Here is the gridview, button control and code from the GetCourseScheduleByCourseID method:

<asp:GridView ID="CourseScheduleGridView" runat="server">
<asp:Button ID="SearchButton" runat="server" Text="Search" OnClick="SearchButton_Click" />
SELECT        Schedule.*
FROM            Schedule
WHERE scheduleID = @course_FKID
8/23/2006 1:48:42 AM
As I have said, it's maybe not your gridview's problem, don't need to convert the courseID to Guid. Plz check the corresponding datatable ScheduleTable's field datatype in your dataset~
你好! Just FYI o_O
8/23/2006 1:59:31 AM


The datatype for the Course_FK is System.Guid as per the xsd file.

8/23/2006 5:45:38 AM
So why not try change datatype for the Course_FK in xsd to System.String? As you use char, varchar of text type for it in DB right?
你好! Just FYI o_O
8/23/2006 6:26:17 AM
I have changed the datatype to System.String and it's still asking for a GUID.
8/24/2006 12:45:42 AM


I've been trying different things to solve this problem myself but no success. Still don't understand why I'm being asked for a GUID datatype?

8/26/2006 12:43:30 AM
Well I found a method called GuidFromString() in VB. It is used in the MSAccess world. I'm assuming that there has to be something similar in CSharp? I get no search results in the MSDN Library when I search for "GuidFromString C Sharp".
8/27/2006 5:52:41 PM

Hey There - this may be a bit late, but you can use this as an example:


That converted a string to a guid for me. 

10/16/2006 4:21:21 AM

Similar Artilces:

Name: haznen Email: haznenatyahoodotcom Product: Gran Paradiso Alpha 8 Summary: '''''''''''''''''''' Comments: '''''''''''''''''''''''''''''''''''' Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a1) Gecko/20061204 UGES/ GranParadiso/3.0a1 From URL: Note to readers: Hendrix gives...

Name: mario Email: ramar17atfastwebnetdotit Product: Gran Paradiso Alpha 2 Summary: ''''' Comments: K: Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a2) Gecko/20070206 GranParadiso/3.0a2 ...

'System.String' to 'System.Guid'
 Hi Guys, I have this working with a hyperlink field in a gridview.   <asp:HyperLinkField DataNavigateUrlFields="UserID" DataNavigateUrlFormatString="userprofiles.aspx?UserID={0}" DataTextField="UserName" HeaderText="User Name" Text="User Name" >  I just want to same thing in a datagrid but I get this error:  <asp:HyperLink ID="HyperLinkToUserProfile" runat="server" NavigateUrl="userprofiles.aspx?UserID={0}"><%# Eval("UserName...

Error 102 Argument '12': cannot convert from 'ref System.Guid' to 'System.Guid?'
Hi  I have a stored proc as follows: USE [SubSrvs]GO/****** Object:  StoredProcedure [dbo].[subsrvs_Services_CreateService]    Script Date: 07/15/2007 11:39:38 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER PROCEDURE [dbo].[subsrvs_Services_CreateService] @Level1    nvarchar(max),    @Level2    nvarchar(max),    @Level3    nvarchar(max),    @Level4    nvarchar(max),    @Level5    nvarchar(max...

Cast from type ''''DBNull'''' to type ''''String'''' is not valid.
How do I avoid getting this error: Cast from type ''''DBNull'''' to type ''''String'''' is not valid. I am trying to get values from the database into a form for updating using a Datareader, SQL is set to allow nulls for certain fields as they are not required but the only way I can get the form to display is by adding a space in SQL. Is there another way around this? Check if it is equal to DBNull.Value first and if it is, don't do the cast.Stanley Tan theSpoke Blog Where in the code does it need to go? I am using the following and it's the profile that isn't always requi...

Convert 'System.DBNull' to type 'System.String' ?
I have a textbox on my site that I want to populate with some data, however when the value is null, which is quite often.The problem is that when I call a static method which returns a string; when that string is DBNull, I get the following error which is absolutely correct.Unable to cast object of type 'System.DBNull' to type 'System.String'.So, what should I do to be able to ignore that the string is null and just display a "" string in the texbox?The code is as follows:    private void GetCartSmall(string sSessionID)    {      &n...

Value of type 'String' cannot be converted to 'System.Net.Mail.MailAddress'
My code is below:Protected Sub btnSendMsg_OnClick(ByVal Source As Object, ByVal E As EventArgs) Dim myMessage As New System.Net.Mail.MailMessage Dim myAttachment As System.Net.Mail.Attachment Dim myMail As System.Net.Mail.SmtpClient If Page.IsValid() Then myMessage.From = txtFromEmail.Text myMessage.To = txtToEmail.TextWhat can I do to fix this? MailMessage.To represents a collection that you Add addresses to.Dim recipient As MailAddress= new MailAddress(txtToEmail.Text) myMessage.To.Add(recipient)    Mike Banavige~~~~~~~~~~...

Value of type 'System.Net.Mail.MailMessage' cannot be converted to 'System.Net.Mail.AlternateView'
Trying to create an alternateview to send a txt email with the html formatted email.  I've used string builder to create the whole email, but I get this error.  Any ideas why?  i've bolded the line that throws the error... Dim EmailBodyTxt As New StringBuilder EmailBodyTxt.Append("<html><style type='text/css'>.table{border:solid; border-color:#006666; width:600;} ")EmailBodyTxt.Append("<body><table class='table'><tr><td colspan='2'><h1>Test<br />RESPONSE SYSTEM</h1></td>...

Object of type 'System.DBNull' cannot be converted to type 'System.String' from formview
I have a formview that I am using for input to my datatable.  I am using an objectdatasource that uses a BLL.  This in turn points to my XSD tableadapter. When I test, and only fill in the required fields, I am getting the error Object of type 'System.DBNull' cannot be converted to type 'System.String' I am not sure what field is having the issue.  In my BLL for the Add, I have checked the dates for null and placed the value of DateTime.MinValue.  For the text fields, I have place "" if they are null.  Is this error being create prior to...

Unable to cast object of type '<>f__AnonymousType1`3[System.Guid,System.String,System.String]' to type 'aspnet_User'.???
Hi everyone, What does this error mean?  ERROR: Unable to cast object of type '<>f__AnonymousType1`3[System.Guid,System.String,System.String]' to type 'aspnet_User'. Thank's a lot /PepePepe JoseNewbie@C#.Net&jRuby What type is in your DataItem?  A Guid? or a String?  Either way, it's telling you cant cast it to a aspnet_User type.  Let us know what your DataItem is and we can help further.Good Luck and happy programming!Let's build community! If my post helped you, mark it as the Answer and I will do the same when you help me.....

'do' won't 'do' if '/'
Greetings to All from Au, Have a NetWare Perl 5.8.4 and wanted to tweak File\Spec\ to try and standardise on '/' separators. If I run a test script (t/uni/lower.t) with an unmodified, it calls t/uni/, that, in, (when the path separators are '\'), the $file is '..\lib\unicore\To\' and the following code portion works, with $simple getting a returned table: sub casetest { my ($base, $spec, $func) = @_; my $file = File::Spec->catfile(File::Spec->catdir(File::Spec->updir, "lib", &qu...

'System.String' to 'System.DateTime' error
Hi, I have a Gridview with templates and i set the format to Text='<%# Eval("PrescriptionDate", "{0:dd/MM/yyyy}") %>'  The objectDataSource: <asp:ObjectDataSource DeleteMethod="DeletePrescriptionDetails" InsertMethod="InsertPrescriptionDetails" ID="objDetails" runat="server" SelectMethod="GetAllPrescriptionDetails" UpdateMethod="UpdatePrescriptionDetails" TypeName="GridViewClasses"> <UpdateParameters> <asp:Parameter Name="PrescriptionId" Type="Int32" /> <asp:Parameter Name="MedicineId" Type="Int32" /> <asp:Parameter Name="ActualDose" Type="I...

Name: L Lachowsky Email: e2brutus_10atyahoodotcom Product: Firefox Summary: ''' Comments: why duddn this surprise me... I change default server from IE to Mozilla, and then i get error messages. well, shud I decide to not get on my computer with Mozilla..or shud I risk security breeches with IE....hmmm at least i can get on the internet with IE Browser Details: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv: Gecko/2008120122 Firefox/3.0.5 From URL: Note to readers: Hendrix gives no expectation of a response to this fee...

System.Net.Mail is giving error CS0029: Cannot implicitly convert type 'string' to 'System.Net.Mail.MailAddress'
I'm getting an error while trying to use the wizard to create a form and than pass it the vaibles to Mail. Any help would be much appreciated. SmtpClient smtpClient = new SmtpClient(); MailMessage message = new MailMessage(); try {   message.From = txtEmail.Text; message.To.Add(""); message.Subject = "Feedback"; message.CC.Add(""); message.CC.Add(""); message.IsBodyHtml = false; message.Body = txtMessage.Text; smtpClient.Send(message); lblStatus.Text = "Email successfully sent."; } catch (Exception ex) { lbl...

Web resources about - Cannot convert value of parameter 'Course_FK' from 'System.String' to 'System.Guid' -

Resources last updated: 1/17/2016 9:54:24 AM