c11ada
c11ada

Reputation: 4334

ASP.NET Conversion failed when converting from a character string to uniqueidentifier

i have a table which has a primary key (UserID) this is of type UniqueIdentifier. im trying to insert a value into this field but i keep getting an error.

i want to get the userID of the current user and insert the into the user_Details table, but i keep getting this error

Conversion failed when converting from a character string to uniqueidentifier

can some one please help me thanks

Upvotes: 2

Views: 2446

Answers (1)

Guffa
Guffa

Reputation: 700730

You have put the parameter inside a string, so it's not identified as a parameter. The effect is that you are trying to convert the string "@UserID" to a GUID instead of using the value in the parameter.

Change the query from

"INSERT INTO  dbo.user_Details(UserId)VALUES ('@UserID')"

to:

"INSERT INTO  dbo.user_Details(UserId)VALUES (@UserID)"

Upvotes: 3

Related Questions