Failed to convert parameter value from string to guid
Asked Answered
P

1

8

I have a tiered application. The datalayer makes a call to the database by using a dataset which contains a tableadapter. In the database table there is a field called ID of type UniqueIdentifier. I then create the following query:

select * from tbl where ID=@ID

When i try to preview the results in the dataset designer i receive the error "Failed to convert parameter value from string to guid".

I tried adding single quotes around the value passed in but didnt work.

Where am i going wrong?

Penicillate answered 10/10, 2012 at 9:59 Comment(0)
A
15

Your column ID is Guid type in your database, but your parameter is a string.

You can convert your parameter to a SqlGuid:

command.Parameters.Add("@GuidParameter", SqlDbType.UniqueIdentifier).Value = new System.Data.SqlTypes.SqlGuid(YourGuid); //The value of @ID

Link : https://msdn.microsoft.com/library/system.data.sqltypes.sqlguid.aspx?f=255&MSPPError=-2147217396

Aparri answered 10/10, 2012 at 10:2 Comment(1)
Thats where i have an issue. I have ONLY created the SQL statement in the query as part of my tableadapter and no where else?Penicillate

© 2022 - 2024 — McMap. All rights reserved.