Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top