Guid handling

I

Igor

Hi

I have a drop down list on my page that lists some items returned from a
database. Each item has its GUID (or uniqueidentifier). I have to (in code
behind of the page) read this GUID, to hand it over to a query (stored
procedure) that takes the GUID and looks for some data in a specific table.
I don't know have to hand it to the query as GUID.

SqlCommand myCommand = new SqlCommand();
myCommand.Connection = myConnection;

myCommand.CommandText = "dbo.tbh_GetBoundIdentifier";
myCommand.CommandType = CommandType.StoredProcedure;

string BoundID =
DropDownList4.SelectedItem.Value.ToString();

SqlParameter myParameter1 = new SqlParameter();
myParameter1.ParameterName = "@BoundID";
myParameter1.SqlDbType = SqlDbType.UniqueIdentifier;
myParameter1.Value = BoundID;

SqlParameter myParameter2 = new SqlParameter();
myParameter2.ParameterName = "@BoundIdentifier";
myParameter2.SqlDbType = SqlDbType.Char;
myParameter2.Direction = ParameterDirection.Output;

myCommand.Parameters.Add(myParameter1);
myCommand.Parameters.Add(myParameter2);

myConnection.Open();

SqlDataReader myReader = myCommand.ExecuteReader();
WIth the code above I get the following error: "Failed to convert parameter
value from a String to a Guid" when trying to execute the command
myCommand.ExecuteReader();. How can I handle (or convert) the GUID so it is
handed as GUID and not as a string?
 
I

Igor

Found solution myself:

Guid BoundID = new Guid(DropDownList4.SelectedItem.Value.ToString());


Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,961
Messages
2,570,131
Members
46,689
Latest member
liammiller

Latest Threads

Top