Solved

Error Message When Performing Update in GridView

Posted on 2008-06-23
8
556 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
DevOps Toolchain Recommendations

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

 
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

DevOps Toolchain Recommendations

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

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

19 Experts available now in Live!

Get 1:1 Help Now