Implicit conversion from data type sql_variant to uniqueidentifer is not allowed.

If you use guids (uniqueidentifiers) in your database in conjunction with ASP.NET SqlDataSource databinding, chances are you'll eventually run into this error "Implicit conversion from data type sql_variant to uniqueidentifer is not allowed. User the CONVERT function to run this query".

Here is a screenshot of the whole error:


The problem is Visual Studio sucks at picking up the fact that this error will occur EVERY SINGLE TIME and continues to let the error happen.

It's easy to fix though. Find your parameters (selectparameters, insertparameters, etc) for the particular statement you're running (select, update, delete, insert). You should see something like this:



The fix is just to remove the Type = "Object" from the parameter that is linked to the uniqueidentifer column in your table. In this case, the controlparameter "CompanyID"  is linked to the companyid column in my companies table. The resulting code should look like this:


Until Next Time...

posted @ Monday, March 23, 2009 11:06 AM

Print

Comments on this entry:

# re: Implicit conversion from data type sql_variant to uniqueidentifer is not allowed.

Left by software developers at 10/22/2009 11:51 AM
Gravatar
Humm... interesting,

This is a great resolution for such a persistant problem,

Thanks for bringing this up

# re: Implicit conversion from data type sql_variant to uniqueidentifer is not allowed.

Left by Web design service at 12/30/2009 3:52 PM
Gravatar
Great guidelines!

# re: Implicit conversion from data type sql_variant to uniqueidentifer is not allowed.

Left by Ravi at 1/12/2010 4:45 AM
Gravatar
Great......!
I was Searching for this Since Last Two weeks

# re: Implicit conversion from data type sql_variant to uniqueidentifer is not allowed.

Left by argent facile au casino at 2/8/2010 11:43 PM
Gravatar
Just wanted to say this is a great post and I used it for a need I had. Though I had a problem with casting database strings to unknown, until run-time, properties. Hope you don't mind I referenced your site on my blog and put up a copy of some of the code you had in the two posts. I linked back to the original.

Your comment:



 (will not be displayed)


 
 
 
Please add 8 and 3 and type the answer here:
 

Live Comment Preview:

 
«March»
SunMonTueWedThuFriSat
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910