Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Guid handling

Reply
Thread Tools

Guid handling

 
 
Igor
Guest
Posts: n/a
 
      06-14-2008
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?


 
Reply With Quote
 
 
 
 
Igor
Guest
Posts: n/a
 
      06-14-2008
Found solution myself:

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


Regards
"Igor" <> wrote in message
news:E5AA5051-C123-4DFF-B978-...
> 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?
>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Here's your GUID Thomas Steinberger MCSE 2 04-06-2005 04:59 PM
Q: Disconnected DataSets - automatic Add/Remove but with Guid Key instead of AutoIncrement int? Sky ASP .Net 2 01-30-2004 09:22 PM
Help with Cisco VPN client 4.0.1 (and 4.0.3) - The VPN client could not find the adapters GUID MP Cisco 2 12-30-2003 03:55 PM
GUID? LL ASP .Net 4 11-04-2003 08:54 PM
305-Exam Guid varsha MCSD 2 10-06-2003 07:19 PM



Advertisments