ASP .NET, GridViews, SqlDataSource, and Guid Parameters

Another thing I ran into today. I actually ran into it awhile back but since I ran into it again today I’d thought I’d post on it to help anyone who happens to find it.

Problem

You have a GridView and a SqlDataSource that takes 1 or more Guids as a Parameter. You use the built in DataSource configuration and it doesn’t give any errors. However, when you actually run it and pass the Guid, you get this error:

“Implicit conversion from data type sql_variant to uniqueidentifier is not allowed. Use the CONVERT function to run this query.”

 Solution

Inside your source look at your DataSource. The parameter tag will look something like this:

<asp:QueryStringParameter Name=”Customer_IID” QueryStringField=”iid” Type=”Object” />

Change the Type to Empty like this:

 

<asp:QueryStringParameter Name=”Customer_IID” QueryStringField=”iid” Type=”Empty” />

I have no clue why Visual Studio 2005 thinks a Guid should be an Object and not an Empty, but this will fix your problems.

 

4 thoughts on “ASP .NET, GridViews, SqlDataSource, and Guid Parameters

  1. awsom! Thank you

    Like

  2. This did the trick. I’ve been working on this all night.

    Like

  3. Thanks for this. Spot on.

    This is still a bug in VS2010 (using Microsoft Visual Web Developer 2010 Express).

    Like

  4. ASP .NET, GridViews, SqlDataSource, and Guid Parameters | Justin Carmony I was recommended this blog by my cousin. I am not sure whether this post is written by him as no one else know such detailed about my trouble. You are wonderful! Thanks! your article about ASP .NET, GridViews, SqlDataSource, and Guid Parameters | Justin CarmonyBest Regards Agata

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this:
search previous next tag category expand menu location phone mail time cart zoom edit close