Solved

Error Message When Performing Update in GridView

Posted on 2008-06-23
8
557 Views
Last Modified: 2013-11-26
I am trying to do a Update in a Gridview however am getting the following Error when I press the update button.  Thanks for the assistance.

Error:
Implicit conversion from data type sql_variant to uniqueidentifier is not allowed. Use the convert function to run the query


<asp:SqlDataSource ID="SqlDataSource2" runat="server" 
        ConnectionString="<%$ ConnectionStrings:SecurityTutorialsConnectionString %>" 
        
        SelectCommand="SELECT [AnnualLeaveRequestId], [UserId], [PayPeriodId], [name], [SelectedDate1], [SelectedDate2], [SelectedDate3], [SelectedDate4], [SelectedDate5], [SelectedDate6], [SelectedDate7], [Status], [Supervisor], [Date] FROM [RPAnnualLeave] WHERE ([name] = @name)" 
        DeleteCommand="DELETE FROM [RPAnnualLeave] WHERE [AnnualLeaveRequestId] = @AnnualLeaveRequestId" 
        InsertCommand="INSERT INTO [RPAnnualLeave] ([AnnualLeaveRequestId], [UserId], [PayPeriodId], [name], [SelectedDate1], [SelectedDate2], [SelectedDate3], [SelectedDate4], [SelectedDate5], [SelectedDate6], [SelectedDate7], [Status], [Supervisor], [Date]) VALUES (@AnnualLeaveRequestId, @UserId, @PayPeriodId, @name, @SelectedDate1, @SelectedDate2, @SelectedDate3, @SelectedDate4, @SelectedDate5, @SelectedDate6, @SelectedDate7, @Status, @Supervisor, @Date)" 
        UpdateCommand="UPDATE [RPAnnualLeave] SET [UserId] = @UserId, [PayPeriodId] = @PayPeriodId, [name] = @name, [SelectedDate1] = @SelectedDate1, [SelectedDate2] = @SelectedDate2, [SelectedDate3] = @SelectedDate3, [SelectedDate4] = @SelectedDate4, [SelectedDate5] = @SelectedDate5, [SelectedDate6] = @SelectedDate6, [SelectedDate7] = @SelectedDate7, [Status] = @Status, [Supervisor] = @Supervisor, [Date] = @Date WHERE [AnnualLeaveRequestId] = @AnnualLeaveRequestId">
        <SelectParameters>

Open in new window

0
Comment
Question by:misnstt
  • 4
  • 2
  • 2
8 Comments
 
LVL 18

Expert Comment

by:jcoehoorn
ID: 21847062
Can you show the <UpdateParameters> section?  That's likely where the error is.
0
 

Author Comment

by:misnstt
ID: 21847163
       <UpdateParameters>
            <asp:Parameter Name="UserId" Type="Object" />
            <asp:Parameter Name="PayPeriodId" Type="Int32" />
            <asp:Parameter Name="name" Type="String" />
            <asp:Parameter Name="SelectedDate1" Type="DateTime" />
            <asp:Parameter Name="SelectedDate2" Type="DateTime" />
            <asp:Parameter Name="SelectedDate3" Type="DateTime" />
            <asp:Parameter Name="SelectedDate4" Type="DateTime" />
            <asp:Parameter Name="SelectedDate5" Type="DateTime" />
            <asp:Parameter Name="SelectedDate6" Type="DateTime" />
            <asp:Parameter Name="SelectedDate7" Type="DateTime" />
            <asp:Parameter Name="Status" Type="String" />
            <asp:Parameter Name="Supervisor" Type="String" />
            <asp:Parameter Name="Date" Type="DateTime" />
            <asp:Parameter Name="AnnualLeaveRequestId" Type="Object" />
        </UpdateParameters>
   
0
 
LVL 2

Expert Comment

by:Alexey_Varlamov
ID: 21847229
The possible problems are in the following strings:

<asp:Parameter Name="UserId" Type="Object" />
<asp:Parameter Name="AnnualLeaveRequestId" Type="Object" />

It should be Guid type?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:misnstt
ID: 21847486
Good Morning,
Thanks for your response.  I am very much a beginner.  I am not sure what you mean by Guid Type or what I need to change.
Thanks
0
 
LVL 18

Expert Comment

by:jcoehoorn
ID: 21847587
<asp:Parameter Name="UserId" Type="System.Guid" />
<asp:Parameter Name="AnnualLeaveRequestId" Type="System.Guid" />
0
 

Author Comment

by:misnstt
ID: 21847792
Hello that didnt help.  When I make those changes I get the error:
The Values permitted For This Attribute Do not Include System.Guid.

0
 
LVL 2

Accepted Solution

by:
Alexey_Varlamov earned 500 total points
ID: 21847945
Ok, try to remove the  Type="Object"  statement and let ASP.NET to detect correct type itself.

Another workaround required little coding: http://weblogs.asp.net/dwahlin/archive/2006/10/10/GUIDs-and-DataSource-Controls.aspx

0
 

Author Closing Comment

by:misnstt
ID: 31469766
Thanks For your help
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question