Guid as a Stored Proc parameter
-
Hi, I have an interesting scenario. I’m trying to pass a GUID to my Sql Parameter in a Stored procedure. First I added the parameter:
command.Parameter.Add(new SqlParameter(“@myID", UniqueIdentifier, 0));
Now, my problem.. The myID GUID comes from a textbox which I generate a Guid.NewGuid() for. When I try to set the parameter value like this:command.Parameter[0].value = textbox.Text;
No this doesn’t work because textbox.Text is a string and therefore the compiler complains when I try that. I have then tried to cast textbox.Text to a GUID like this:command.Parameter[0].value = (Guid)textbox.Text;
No once again the compiler complains cause it wont let you cast a string to a Guid. Any ideas for me please? Thanks. R -
Hi, I have an interesting scenario. I’m trying to pass a GUID to my Sql Parameter in a Stored procedure. First I added the parameter:
command.Parameter.Add(new SqlParameter(“@myID", UniqueIdentifier, 0));
Now, my problem.. The myID GUID comes from a textbox which I generate a Guid.NewGuid() for. When I try to set the parameter value like this:command.Parameter[0].value = textbox.Text;
No this doesn’t work because textbox.Text is a string and therefore the compiler complains when I try that. I have then tried to cast textbox.Text to a GUID like this:command.Parameter[0].value = (Guid)textbox.Text;
No once again the compiler complains cause it wont let you cast a string to a Guid. Any ideas for me please? Thanks. RRyno Burger wrote:
Any ideas for me please?
The Guid constructor[^] takes a string.
Upcoming events: * Glasgow Geek Dinner (5th March) * Glasgow: Tell us what you want to see in 2007 My: Website | Blog | Photos