Uniqueidentifier data type in a parameter

When you create a parameter in VS for a SqlDataSource, the IDE add Type="Object" to the parameter. The query will not work without some modification. Here is a quick fix for this problem: Simply remove the type="Object" from the parameter and keep everything else as is.
Another way to solve this problem is to CAST the parameter to uniqueidenifier explicitly in the WHERE clause.
The following solution is what I used to answer a question for a querystringparameter:
1. Try this simple fix: remove Type="Object" from your querystringparameter.

<asp:QueryStringParameter Name="UserId" QueryStringField="UserID" />


2. Add a CAST to your parameter in the WHERE clause if you do keepthe Type="Object" in the queryparameter:

…WHERE ([Userid] = CAST(@UseIid as uniqueidentifier))


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 )

Google photo

You are commenting using your Google 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