7

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?

1 Answers1

14

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

d219
  • 2,707
  • 5
  • 31
  • 36
Aghilas Yakoub
  • 28,516
  • 5
  • 46
  • 51
  • 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? –  Oct 10 '12 at 10:37