Operand type clash: timestamp is incompatible with sql_variant
It appears that the problem is that the value for the Type property of the Parameter (which was generated by the SqlDataSource wizard) is Object which maps to 'sql_variant' rather than to 'timestamp'.
I know that the older way of doing things with SqlDataAdapter, SqlCommand, SqlParameter can handle timestamps because SqlParameter has a SqlDbType that can have a value of SqlDbType.Timestamp, but I don't see how to do this with the newer SqlDataSource, Parameter classes because the Parameter.Type property (of type TypeCode) doesn't have a Timestamp value.
Has anyone been able to use a 'timestamp' type field with SqlDataSource
Here's my sample code:
<%
@ Page Language="C#" AutoEventWireup="true" CodeFile="MyTestPage.aspx.cs" Inherits="MyTestPage" %><!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><
html xmlns="http://www.w3.org/1999/xhtml" ><
head runat="server"> <title>Untitled Page</title></
head><
body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to display." DataKeyNames="MyID"> <Columns> <asp:CommandField ShowEditButton="True" /> <asp:BoundField DataField="MyID" HeaderText="MyID" InsertVisible="False" ReadOnly="True" SortExpression="MyID" /> <asp:BoundField DataField="MyDesc" HeaderText="MyDesc" SortExpression="MyDesc" /> </Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues" ConnectionString="<%$ ConnectionStrings:CtrlConnectionString1 %>" DeleteCommand="DELETE FROM [MyTest] WHERE [MyID] = @original_MyID AND [MyDesc] = @original_MyDesc AND [timestamp] = @original_timestamp" InsertCommand="INSERT INTO [MyTest] ([MyDesc], [timestamp]) VALUES (@MyDesc, @timestamp)" OldValuesParameterFormatString="original_{0}" ProviderName="<%$ ConnectionStrings:CtrlConnectionString1.ProviderName %>" SelectCommand="SELECT [MyID], [MyDesc], [timestamp] FROM [MyTest]" UpdateCommand="UPDATE [MyTest] SET [MyDesc] = @MyDesc WHERE [MyID] = @original_MyID AND [MyDesc] = @original_MyDesc AND [timestamp] = @original_timestamp"> <DeleteParameters> <asp:Parameter Name="original_MyID" Type="Int32" /> <asp:Parameter Name="original_MyDesc" Type="String" /> <asp:Parameter Name="original_timestamp" Type="Object" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="MyDesc" Type="String" /> <asp:Parameter Name="timestamp" Type="Object" /> <asp:Parameter Name="original_MyID" Type="Int32" /> <asp:Parameter Name="original_MyDesc" Type="String" /> <asp:Parameter Name="original_timestamp" Type="Object" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="MyDesc" Type="String" /> <asp:Parameter Name="timestamp" Type="Object" /> </InsertParameters> </asp:SqlDataSource> </div> </form></
body></
html>
Timestamp concurrency control with SQLDataSource
Julien Lavigne du Cadet
Mieux
You will get a better answer in the http://forums.asp.net groups, try the data access groups on the site.
In this group you will generally see people answering questions on Installing and registering the express products, for the general use it is better to post in the specific language or technology groups.