VS 2005: Gotcha DataGrid Dataset and uniqueidentifier (GUIDS)

Published 03 August 06 06:19 | Simon Phillips

I've never been a great fan of the point and click nature of the DataGrid in .Net, it all seams too easy and there was always the problem with the bloat that was the ViewState.

I'm having to put together a quick proto-type atm so I'm just dragging and dropping controls as fast as my little mouse can go ;). I hit a problem when I was trying to update a GUID though the Edit / Update.

The problem is not with the DataGrid itself but with the underlying DataSource. The problem is that is by default the dataset asp:parameters convert any GUID (uniqueidentifier in SQL) to a object type.

 

1 <asp:SqlDataSource ...> 2 <InsertParameters> 3 <asp:Parameter Name="UserId" Type="Object" /> 4 ... 5 </InsertParameters> 6 </asp:SqlDataSource>

 

This is a bug that was noted in Beta 2 but got in to production. The work around is if you remove the Type="Object" then it work.

 

1 <asp:SqlDataSource ...> 2 <InsertParameters> 3 <asp:Parameter Name="UserId" Type="Object" /> 4 ... 5 </InsertParameters> 6 </asp:SqlDataSource>

 

Thanks to Scott Mitchell Inserting with a SqlDataSource Using uniqueidentifier Parameters

Comments

# Damien McGivern said on August 15, 2006 08:31 :

I just got caught out by this for the first time today, but after reading this post identified the problem straight away.

Cheers!