Solved

Error Message When Performing Update in GridView

Posted on 2008-06-23
8
555 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
 

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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now