Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Passing a Guid to a Stored Procedure

Author  Topic 

Skydolphin
Starting Member

43 Posts

Posted - 2005-01-13 : 17:06:45
What is the correct syntax for passing a guid to a Sproc in C#. I'm getting an Invalid cast from System.String to System.Guid error.

SqlCommand cmd2 = new SqlCommand("proc_Reports_GetSiteInfo", connection);
cmd2.CommandType = CommandType.StoredProcedure;

SqlParameter Parm = cmd2.Parameters.Add("@SiteID", SqlDbType.UniqueIdentifier);

I've tried the following.
Parm.Value = "'{" + drv["SiteID"] + "}'";
Parm.Value = "'{" + drv["SiteID"].ToString() + "}'";
Parm.Value = drv["SiteID"].ToString();
Parm.Value = drv["SiteID"];

Any help would be appreciated. I can't figure out what it wants.

Thanks,

Rhonda

Rhonda

Skydolphin
Starting Member

43 Posts

Posted - 2005-01-13 : 17:12:42
I figured out my problem. I was using a field returned from an ealier sproc and it was returning it as a system.string instead of system.guid. DUH!!!

Rhonda

Rhonda
Go to Top of Page
   

- Advertisement -