Failed to convert parameter value from string to guid

jamie_pattison

Well-known member
Joined
Sep 9, 2008
Messages
116
Programming Experience
Beginner
In my database table i have a field that is of type UniqueIdentifier. I then have a tableadapter in my dataset (of course in a project) that contains a query as below

select name, address1, address2 from myTable where ID=@ID

ID is the field that is of type UniqueIdentifier. When i run the above query (by selecting Preview data) i get the error "failed to convert parameter value from string to guid"

How could i resolve this?

Thanks
 
Hi,

From what I can see you need to encase your @ID parameter in single quotes. i.e. where ID = '@ID'

Cheers,

Ian

Thanks i tried that but it didnt work. It treated it as a passed in value therefore no parameter was accepted. I tried adding single quotes around value im passing in too (When you click Preview Data i added the single quotes in the box at the top) which didnt work either.
 
Try changing your query to :
VB.NET:
select name, address1, address2 from myTable where CONVERT(char(255), ID) = @ID

Check the documentation on UniqueIdentifier uniqueidentifier (Transact-SQL)
 
Well it'll probably do the trick, however I'm pretty sure it's not optimal to have type conversions in the WHERE clause.

Of course the ideal solution would be to change the table schema to use something a little more friendly for the UID, say an INT column, that could be used without conversion - the OP may not have that luxury though.
 
Back
Top