Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / ASP.NET

Uniqueidentifier Field Problem

0.00/5 (No votes)
2 Oct 2010CPOL 9.2K  
One of the problems i faced, when i try to update a record with a "ueidentifier" field. using SqlDataSource.. it was giving me the following error:

CSS
Object must implement IConvertible.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Object must implement IConvertible.



Solution

The crux of the problem, it appears, is that the <asp:Parameter> value for the uniqueidentifier field is, by default, set to Type="Object". To fix this, simply remove the Type property altogether. That is, change the SqlDataSource parameter setting from something like:



XML
<asp:SqlDataSource ...>
  <InsertParameters>
    <asp:Parameter Name="UserId" Type="Object" />
    ...
  </InsertParameters>
</asp:SqlDataSource>

to:

<asp:SqlDataSource ...>
  <InsertParameters>
    <asp:Parameter Name="UserId"  />
    ...
  </InsertParameters>
</asp:SqlDataSource>

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)