473,395 Members | 1,666 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Optimistic concurrency in custom GridView/SqlDataSource

I've chosen to implement the "optimistic concurrency" model in my
application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to
my main tables. I read the value of the column in my select, remember it, and
then use it in the update. It works just fine when I have full control of the
whole process.

I want to do the same for my GridView/SqlDataSource combinations. I
typically select from a view and update the corresponding table.

Simply adding a RowVersion column to my GridView and @RowVersion to the
UpdateCommand results in a [Must declare the scalar variable "@RowVersion"]
error.

The other columns auto magically get carried over from the select into the
update, why doesn't the RowVersion?

Here's the code:

<asp:GridView ID="GridViewSharePartners" runat="server"
AutoGenerateColumns="False"
DataKeyNames="dbIDAntennaOwner,dbIDSite"
DataSourceID="SharePartnerList" EmptyDataText="No Partners on record for this
Site"
Width="549px"
OnRowEditing="GridViewSharePartners_RowEditing" >
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="dbIDSite"
HeaderText="dbIDSite" ReadOnly="True" SortExpression="dbIDSite"
Visible="False" />
<asp:BoundField DataField="dbIDAntennaOwner"
HeaderText="dbIDAntennaOwner" ReadOnly="True"
SortExpression="dbIDAntennaOwner" Visible="False" />
<asp:BoundField DataField="Name" HeaderText="Name"
ReadOnly="True" SortExpression="Name" />
<asp:BoundField DataField="PartnerSiteID"
HeaderText="PartnerSiteID" SortExpression="PartnerSiteID" />
<asp:BoundField DataField="Comments"
HeaderText="Comments" SortExpression="Comments" />
<asp:BoundField DataField="RowVersion"
HeaderText="RowVersion" SortExpression="RowVersion" ReadOnly="True"
Visible="False" />
</Columns>
<HeaderStyle HorizontalAlign="Left" />
</asp:GridView>
<asp:SqlDataSource ID="SharePartnerList" runat="server"
ConnectionString="<%$ ConnectionStrings:VodacomEMRConnectionString %>"
SelectCommand="SELECT * FROM vw_SharePartner WHERE
dbIDSite = @siteID"
UpdateCommand="UPDATE SharePartner SET PartnerSiteID =
@PartnerSiteID, Comments = @Comments, UserName = @userName WHERE (dbIDSite =
@dbIDSite) AND (dbIDAntennaOwner = @dbIDAntennaOwner) ">
<UpdateParameters>
<asp:SessionParameter Name="userName"
SessionField="UserName" Type="String" />
<asp:QueryStringParameter Name="siteID"
QueryStringField="siteID" Type="Int32" />
</UpdateParameters>
<SelectParameters>
<asp:QueryStringParameter Name="siteID"
QueryStringField="siteID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>

Nov 19 '05 #1
8 5002
Hi Mike,

Welcome to ASPNET newsgroup.
Regarding on the doing Optimistic concrrency data updating in asp.net 2.0
by GridView/SqlDatasource problem, from the code template you provided the
SqlDataSource's update statement is as below:

UpdateCommand="UPDATE SharePartner SET PartnerSiteID =
@PartnerSiteID, Comments = @Comments, UserName = @userName WHERE (dbIDSite
=
@dbIDSite) AND (dbIDAntennaOwner = @dbIDAntennaOwner) ">

I haven't found that you use the "RowVersion" field to perform version
comparation. Also, since the error message you encountered was:
==========
[Must declare the scalar variable "@RowVersion"]
error.
==========

So I think this maybe the problem. Have you tried add the @RowVersion
parameter declaration in the update statement also to see whether it helps?

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| Thread-Topic: Optimistic concurrency in custom GridView/SqlDataSource
| thread-index: AcXl1JPHnaT1k9/rQXKswscmduC8lw==
| X-WBNR-Posting-Host: 198.54.202.242
| From: "=?Utf-8?B?TWlrZSBLZWxseQ==?=" <Mi*******@community.nospam>
| Subject: Optimistic concurrency in custom GridView/SqlDataSource
| Date: Thu, 10 Nov 2005 00:56:02 -0800
| Lines: 64
| Message-ID: <2F**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:356949
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| I've chosen to implement the "optimistic concurrency" model in my
| application. To assist in that, I've added a ROWVERSION (TIMESTAMP)
column to
| my main tables. I read the value of the column in my select, remember it,
and
| then use it in the update. It works just fine when I have full control of
the
| whole process.
|
| I want to do the same for my GridView/SqlDataSource combinations. I
| typically select from a view and update the corresponding table.
|
| Simply adding a RowVersion column to my GridView and @RowVersion to the
| UpdateCommand results in a [Must declare the scalar variable
"@RowVersion"]
| error.
|
| The other columns auto magically get carried over from the select into
the
| update, why doesn't the RowVersion?
|
| Here's the code:
|
| <asp:GridView ID="GridViewSharePartners" runat="server"
| AutoGenerateColumns="False"
| DataKeyNames="dbIDAntennaOwner,dbIDSite"
| DataSourceID="SharePartnerList" EmptyDataText="No Partners on record for
this
| Site"
| Width="549px"
| OnRowEditing="GridViewSharePartners_RowEditing" >
| <Columns>
| <asp:CommandField ShowEditButton="True" />
| <asp:BoundField DataField="dbIDSite"
| HeaderText="dbIDSite" ReadOnly="True" SortExpression="dbIDSite"
| Visible="False" />
| <asp:BoundField DataField="dbIDAntennaOwner"
| HeaderText="dbIDAntennaOwner" ReadOnly="True"
| SortExpression="dbIDAntennaOwner" Visible="False" />
| <asp:BoundField DataField="Name"
HeaderText="Name"
| ReadOnly="True" SortExpression="Name" />
| <asp:BoundField DataField="PartnerSiteID"
| HeaderText="PartnerSiteID" SortExpression="PartnerSiteID" />
| <asp:BoundField DataField="Comments"
| HeaderText="Comments" SortExpression="Comments" />
| <asp:BoundField DataField="RowVersion"
| HeaderText="RowVersion" SortExpression="RowVersion" ReadOnly="True"
| Visible="False" />
| </Columns>
| <HeaderStyle HorizontalAlign="Left" />
| </asp:GridView>
| <asp:SqlDataSource ID="SharePartnerList" runat="server"
| ConnectionString="<%$ ConnectionStrings:VodacomEMRConnectionString %>"
| SelectCommand="SELECT * FROM vw_SharePartner WHERE
| dbIDSite = @siteID"
| UpdateCommand="UPDATE SharePartner SET PartnerSiteID
=
| @PartnerSiteID, Comments = @Comments, UserName = @userName WHERE
(dbIDSite =
| @dbIDSite) AND (dbIDAntennaOwner = @dbIDAntennaOwner) ">
| <UpdateParameters>
| <asp:SessionParameter Name="userName"
| SessionField="UserName" Type="String" />
| <asp:QueryStringParameter Name="siteID"
| QueryStringField="siteID" Type="Int32" />
| </UpdateParameters>
| <SelectParameters>
| <asp:QueryStringParameter Name="siteID"
| QueryStringField="siteID" Type="Int32" />
| </SelectParameters>
| </asp:SqlDataSource>
|
|

Nov 19 '05 #2
Hi Steven.

No offence, but I think you missed the point. Thanks for the reply, though.

The code I posted works. It updates the selected row as expected. It is when
I add RowVersion to the code that it I get the error. So, if I change the
update statement to read "UPDATE SharePartner SET PartnerSiteID =
@PartnerSiteID, Comments = @Comments, UserName = @userName WHERE (dbIDSite =
@dbIDSite) AND (dbIDAntennaOwner = @dbIDAntennaOwner) AND (RowVersion =
@RowVersion)" then I get the error message indicated. Adding a parameter
called "RowVersion" takes away the error message, but my update then fails
(no records updated).

The part I don't understand is that I don't specify parameters for the other
columns, why should I do so for the RowVersion?

"Steven Cheng[MSFT]" wrote:
Hi Mike,

Welcome to ASPNET newsgroup.
Regarding on the doing Optimistic concrrency data updating in asp.net 2.0
by GridView/SqlDatasource problem, from the code template you provided the
SqlDataSource's update statement is as below:

UpdateCommand="UPDATE SharePartner SET PartnerSiteID =
@PartnerSiteID, Comments = @Comments, UserName = @userName WHERE (dbIDSite
=
@dbIDSite) AND (dbIDAntennaOwner = @dbIDAntennaOwner) ">

I haven't found that you use the "RowVersion" field to perform version
comparation. Also, since the error message you encountered was:
==========
[Must declare the scalar variable "@RowVersion"]
error.
==========

So I think this maybe the problem. Have you tried add the @RowVersion
parameter declaration in the update statement also to see whether it helps?

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| Thread-Topic: Optimistic concurrency in custom GridView/SqlDataSource
| thread-index: AcXl1JPHnaT1k9/rQXKswscmduC8lw==
| X-WBNR-Posting-Host: 198.54.202.242
| From: "=?Utf-8?B?TWlrZSBLZWxseQ==?=" <Mi*******@community.nospam>
| Subject: Optimistic concurrency in custom GridView/SqlDataSource
| Date: Thu, 10 Nov 2005 00:56:02 -0800
| Lines: 64
| Message-ID: <2F**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:356949
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| I've chosen to implement the "optimistic concurrency" model in my
| application. To assist in that, I've added a ROWVERSION (TIMESTAMP)
column to
| my main tables. I read the value of the column in my select, remember it,
and
| then use it in the update. It works just fine when I have full control of
the
| whole process.
|
| I want to do the same for my GridView/SqlDataSource combinations. I
| typically select from a view and update the corresponding table.
|
| Simply adding a RowVersion column to my GridView and @RowVersion to the
| UpdateCommand results in a [Must declare the scalar variable
"@RowVersion"]
| error.
|
| The other columns auto magically get carried over from the select into
the
| update, why doesn't the RowVersion?
|
| Here's the code:
|
| <asp:GridView ID="GridViewSharePartners" runat="server"
| AutoGenerateColumns="False"
| DataKeyNames="dbIDAntennaOwner,dbIDSite"
| DataSourceID="SharePartnerList" EmptyDataText="No Partners on record for
this
| Site"
| Width="549px"
| OnRowEditing="GridViewSharePartners_RowEditing" >
| <Columns>
| <asp:CommandField ShowEditButton="True" />
| <asp:BoundField DataField="dbIDSite"
| HeaderText="dbIDSite" ReadOnly="True" SortExpression="dbIDSite"
| Visible="False" />
| <asp:BoundField DataField="dbIDAntennaOwner"
| HeaderText="dbIDAntennaOwner" ReadOnly="True"
| SortExpression="dbIDAntennaOwner" Visible="False" />
| <asp:BoundField DataField="Name"
HeaderText="Name"
| ReadOnly="True" SortExpression="Name" />
| <asp:BoundField DataField="PartnerSiteID"
| HeaderText="PartnerSiteID" SortExpression="PartnerSiteID" />
| <asp:BoundField DataField="Comments"
| HeaderText="Comments" SortExpression="Comments" />
| <asp:BoundField DataField="RowVersion"
| HeaderText="RowVersion" SortExpression="RowVersion" ReadOnly="True"
| Visible="False" />
| </Columns>
| <HeaderStyle HorizontalAlign="Left" />
| </asp:GridView>
| <asp:SqlDataSource ID="SharePartnerList" runat="server"
| ConnectionString="<%$ ConnectionStrings:VodacomEMRConnectionString %>"
| SelectCommand="SELECT * FROM vw_SharePartner WHERE
| dbIDSite = @siteID"
| UpdateCommand="UPDATE SharePartner SET PartnerSiteID
=
| @PartnerSiteID, Comments = @Comments, UserName = @userName WHERE
(dbIDSite =
| @dbIDSite) AND (dbIDAntennaOwner = @dbIDAntennaOwner) ">
| <UpdateParameters>
| <asp:SessionParameter Name="userName"
| SessionField="UserName" Type="String" />
| <asp:QueryStringParameter Name="siteID"
| QueryStringField="siteID" Type="Int32" />
| </UpdateParameters>
| <SelectParameters>
| <asp:QueryStringParameter Name="siteID"
| QueryStringField="siteID" Type="Int32" />
| </SelectParameters>
| </asp:SqlDataSource>
|
|

Nov 19 '05 #3
Thanks for your further description and sorry for my misunderstanding,

I'd like to perform some local tests according to your scenarion, would you
try providing me a simple complete page and code list, also it possible the
complete test database structure would be necessary.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Thread-Topic: Optimistic concurrency in custom GridView/SqlDataSource
| thread-index: AcXmkkn3ShM1FjCrR9uiEzCRTh5HhQ==
| X-WBNR-Posting-Host: 198.54.202.242
| From: "=?Utf-8?B?TWlrZSBLZWxseQ==?=" <Mi*******@community.nospam>
| References: <2F**********************************@microsoft.co m>
<0c**************@TK2MSFTNGXA02.phx.gbl>
| Subject: RE: Optimistic concurrency in custom GridView/SqlDataSource
| Date: Thu, 10 Nov 2005 23:34:03 -0800
| Lines: 154
| Message-ID: <E0**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:357293
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hi Steven.
|
| No offence, but I think you missed the point. Thanks for the reply,
though.
|
| The code I posted works. It updates the selected row as expected. It is
when
| I add RowVersion to the code that it I get the error. So, if I change the
| update statement to read "UPDATE SharePartner SET PartnerSiteID =
| @PartnerSiteID, Comments = @Comments, UserName = @userName WHERE
(dbIDSite =
| @dbIDSite) AND (dbIDAntennaOwner = @dbIDAntennaOwner) AND (RowVersion =
| @RowVersion)" then I get the error message indicated. Adding a parameter
| called "RowVersion" takes away the error message, but my update then
fails
| (no records updated).
|
| The part I don't understand is that I don't specify parameters for the
other
| columns, why should I do so for the RowVersion?
|
| "Steven Cheng[MSFT]" wrote:
|
| > Hi Mike,
| >
| > Welcome to ASPNET newsgroup.
| > Regarding on the doing Optimistic concrrency data updating in asp.net
2.0
| > by GridView/SqlDatasource problem, from the code template you provided
the
| > SqlDataSource's update statement is as below:
| >
| > UpdateCommand="UPDATE SharePartner SET PartnerSiteID =
| > @PartnerSiteID, Comments = @Comments, UserName = @userName WHERE
(dbIDSite
| > =
| > @dbIDSite) AND (dbIDAntennaOwner = @dbIDAntennaOwner) ">
| >
| > I haven't found that you use the "RowVersion" field to perform version
| > comparation. Also, since the error message you encountered was:
| > ==========
| > [Must declare the scalar variable "@RowVersion"]
| > error.
| > ==========
| >
| > So I think this maybe the problem. Have you tried add the @RowVersion
| > parameter declaration in the update statement also to see whether it
helps?
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| >
| >
| >
| > --------------------
| > | Thread-Topic: Optimistic concurrency in custom GridView/SqlDataSource
| > | thread-index: AcXl1JPHnaT1k9/rQXKswscmduC8lw==
| > | X-WBNR-Posting-Host: 198.54.202.242
| > | From: "=?Utf-8?B?TWlrZSBLZWxseQ==?=" <Mi*******@community.nospam>
| > | Subject: Optimistic concurrency in custom GridView/SqlDataSource
| > | Date: Thu, 10 Nov 2005 00:56:02 -0800
| > | Lines: 64
| > | Message-ID: <2F**********************************@microsoft.co m>
| > | MIME-Version: 1.0
| > | Content-Type: text/plain;
| > | charset="Utf-8"
| > | Content-Transfer-Encoding: 7bit
| > | X-Newsreader: Microsoft CDO for Windows 2000
| > | Content-Class: urn:content-classes:message
| > | Importance: normal
| > | Priority: normal
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| > | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGXA03.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:356949
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | I've chosen to implement the "optimistic concurrency" model in my
| > | application. To assist in that, I've added a ROWVERSION (TIMESTAMP)
| > column to
| > | my main tables. I read the value of the column in my select, remember
it,
| > and
| > | then use it in the update. It works just fine when I have full
control of
| > the
| > | whole process.
| > |
| > | I want to do the same for my GridView/SqlDataSource combinations. I
| > | typically select from a view and update the corresponding table.
| > |
| > | Simply adding a RowVersion column to my GridView and @RowVersion to
the
| > | UpdateCommand results in a [Must declare the scalar variable
| > "@RowVersion"]
| > | error.
| > |
| > | The other columns auto magically get carried over from the select
into
| > the
| > | update, why doesn't the RowVersion?
| > |
| > | Here's the code:
| > |
| > | <asp:GridView ID="GridViewSharePartners"
runat="server"
| > | AutoGenerateColumns="False"
| > | DataKeyNames="dbIDAntennaOwner,dbIDSite"
| > | DataSourceID="SharePartnerList" EmptyDataText="No Partners on record
for
| > this
| > | Site"
| > | Width="549px"
| > | OnRowEditing="GridViewSharePartners_RowEditing" >
| > | <Columns>
| > | <asp:CommandField ShowEditButton="True" />
| > | <asp:BoundField DataField="dbIDSite"
| > | HeaderText="dbIDSite" ReadOnly="True" SortExpression="dbIDSite"
| > | Visible="False" />
| > | <asp:BoundField DataField="dbIDAntennaOwner"
| > | HeaderText="dbIDAntennaOwner" ReadOnly="True"
| > | SortExpression="dbIDAntennaOwner" Visible="False" />
| > | <asp:BoundField DataField="Name"
| > HeaderText="Name"
| > | ReadOnly="True" SortExpression="Name" />
| > | <asp:BoundField DataField="PartnerSiteID"
| > | HeaderText="PartnerSiteID" SortExpression="PartnerSiteID" />
| > | <asp:BoundField DataField="Comments"
| > | HeaderText="Comments" SortExpression="Comments" />
| > | <asp:BoundField DataField="RowVersion"
| > | HeaderText="RowVersion" SortExpression="RowVersion" ReadOnly="True"
| > | Visible="False" />
| > | </Columns>
| > | <HeaderStyle HorizontalAlign="Left" />
| > | </asp:GridView>
| > | <asp:SqlDataSource ID="SharePartnerList"
runat="server"
| > | ConnectionString="<%$ ConnectionStrings:VodacomEMRConnectionString
%>"
| > | SelectCommand="SELECT * FROM vw_SharePartner
WHERE
| > | dbIDSite = @siteID"
| > | UpdateCommand="UPDATE SharePartner SET
PartnerSiteID
| > =
| > | @PartnerSiteID, Comments = @Comments, UserName = @userName WHERE
| > (dbIDSite =
| > | @dbIDSite) AND (dbIDAntennaOwner = @dbIDAntennaOwner) ">
| > | <UpdateParameters>
| > | <asp:SessionParameter Name="userName"
| > | SessionField="UserName" Type="String" />
| > | <asp:QueryStringParameter Name="siteID"
| > | QueryStringField="siteID" Type="Int32" />
| > | </UpdateParameters>
| > | <SelectParameters>
| > | <asp:QueryStringParameter Name="siteID"
| > | QueryStringField="siteID" Type="Int32" />
| > | </SelectParameters>
| > | </asp:SqlDataSource>
| > |
| > |
| >
| >
|

Nov 19 '05 #4
Here is a simple mockup page that models the problem.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

<!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" DataKeyNames="id"
DataSourceID="SqlDataSourceOptimistic">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="id" HeaderText="id"
InsertVisible="False" ReadOnly="True"
SortExpression="id" />
<asp:BoundField DataField="name" HeaderText="name"
SortExpression="name" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSourceOptimistic" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:PlayConnectionString %>"
DeleteCommand="DELETE FROM [Optimistic] WHERE [id] = @original_id AND [name]
= @original_name AND [rowversion] = @original_rowversion"
InsertCommand="INSERT INTO [Optimistic] ([name], [rowversion])
VALUES (@name, @rowversion)"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT * FROM [Optimistic]"
UpdateCommand="UPDATE [Optimistic] SET [name] = @name,
[rowversion] = @rowversion WHERE [id] = @original_id AND [name] =
@original_name AND [rowversion] = @original_rowversion">
<DeleteParameters>
<asp:Parameter Name="original_id" Type="Int32" />
<asp:Parameter Name="original_name" Type="String" />
<asp:Parameter Name="original_rowversion" Type="Object" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="rowversion" Type="Object" />
<asp:Parameter Name="original_id" Type="Int32" />
<asp:Parameter Name="original_name" Type="String" />
<asp:Parameter Name="original_rowversion" Type="Object" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="rowversion" Type="Object" />
</InsertParameters>
</asp:SqlDataSource>

</div>
</form>
</body>
</html>

Here's the corresponding table:

CREATE TABLE [dbo].[Optimistic](
[id] [int] IDENTITY(1,1) NOT NULL,
[name] [varchar](50) NULL,
[rowversion] [timestamp] NOT NULL,
CONSTRAINT [PK_Optimistic] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO

Nov 19 '05 #5
Thanks for your followup and the code, I'll make some tests and update you
soon.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Thread-Topic: Optimistic concurrency in custom GridView/SqlDataSource
| thread-index: AcXo/W8zDm9eKpv+TnG/WBTPf+bdaw==
| X-WBNR-Posting-Host: 198.54.202.242
| From: "=?Utf-8?B?TWlrZSBLZWxseQ==?=" <Mi*******@community.nospam>
| References: <2F**********************************@microsoft.co m>
<0c**************@TK2MSFTNGXA02.phx.gbl>
<E0**********************************@microsoft.co m>
<Hm**************@TK2MSFTNGXA02.phx.gbl>
| Subject: RE: Optimistic concurrency in custom GridView/SqlDataSource
| Date: Mon, 14 Nov 2005 01:26:04 -0800
| Lines: 76
| Message-ID: <7D**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSF TNGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:357860
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Here is a simple mockup page that models the problem.
|
| <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
| Inherits="_Default" %>
|
| <!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" DataKeyNames="id"
| DataSourceID="SqlDataSourceOptimistic">
| <Columns>
| <asp:CommandField ShowEditButton="True" />
| <asp:BoundField DataField="id" HeaderText="id"
| InsertVisible="False" ReadOnly="True"
| SortExpression="id" />
| <asp:BoundField DataField="name" HeaderText="name"
| SortExpression="name" />
| </Columns>
| </asp:GridView>
| <asp:SqlDataSource ID="SqlDataSourceOptimistic" runat="server"
| ConflictDetection="CompareAllValues"
| ConnectionString="<%$ ConnectionStrings:PlayConnectionString
%>"
| DeleteCommand="DELETE FROM [Optimistic] WHERE [id] = @original_id AND
[name]
| = @original_name AND [rowversion] = @original_rowversion"
| InsertCommand="INSERT INTO [Optimistic] ([name],
[rowversion])
| VALUES (@name, @rowversion)"
| OldValuesParameterFormatString="original_{0}"
| SelectCommand="SELECT * FROM [Optimistic]"
| UpdateCommand="UPDATE [Optimistic] SET [name] = @name,
| [rowversion] = @rowversion WHERE [id] = @original_id AND [name] =
| @original_name AND [rowversion] = @original_rowversion">
| <DeleteParameters>
| <asp:Parameter Name="original_id" Type="Int32" />
| <asp:Parameter Name="original_name" Type="String" />
| <asp:Parameter Name="original_rowversion" Type="Object" />
| </DeleteParameters>
| <UpdateParameters>
| <asp:Parameter Name="name" Type="String" />
| <asp:Parameter Name="rowversion" Type="Object" />
| <asp:Parameter Name="original_id" Type="Int32" />
| <asp:Parameter Name="original_name" Type="String" />
| <asp:Parameter Name="original_rowversion" Type="Object" />
| </UpdateParameters>
| <InsertParameters>
| <asp:Parameter Name="name" Type="String" />
| <asp:Parameter Name="rowversion" Type="Object" />
| </InsertParameters>
| </asp:SqlDataSource>
|
| </div>
| </form>
| </body>
| </html>
|
| Here's the corresponding table:
|
| CREATE TABLE [dbo].[Optimistic](
| [id] [int] IDENTITY(1,1) NOT NULL,
| [name] [varchar](50) NULL,
| [rowversion] [timestamp] NOT NULL,
| CONSTRAINT [PK_Optimistic] PRIMARY KEY CLUSTERED
| (
| [id] ASC
| )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
| ) ON [PRIMARY]
|
| GO
|
|

Nov 19 '05 #6
Hi Mike,

I've just made some testing according to the code and database you
provided. Seems that the problem is somewhat related to the timestamp
sqltype's mapping in the .NET SqlDataSource control and GridView. From my
test, the SqlDataSource will mapp the timestamp column to an "Object" type
in DataSource's parameter, however, this type seem not able to persisted
the timestamp value. So when updating ,the value can not be actually passed
back to the SqlDataSource ... So I'm thinking that we may need to define
a custom template fields to store this timestamp value and manually adding
it into the updating parameter's collection through the GridView's updating
event...

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| X-Tomcat-ID: 299505317
| References: <2F**********************************@microsoft.co m>
<0c**************@TK2MSFTNGXA02.phx.gbl>
<E0**********************************@microsoft.co m>
<Hm**************@TK2MSFTNGXA02.phx.gbl>
<7D**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From: st*****@online.microsoft.com (Steven Cheng[MSFT])
| Organization: Microsoft
| Date: Tue, 15 Nov 2005 14:22:29 GMT
| Subject: RE: Optimistic concurrency in custom GridView/SqlDataSource
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| Message-ID: <F9**************@TK2MSFTNGXA02.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Lines: 118
| Path: TK2MSFTNGXA02.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:358233
| NNTP-Posting-Host: tomcatimport2.phx.gbl 10.201.218.182
|
| Thanks for your followup and the code, I'll make some tests and update
you
| soon.
|
| Thanks,
|
| Steven Cheng
| Microsoft Online Support
|
| Get Secure! www.microsoft.com/security
| (This posting is provided "AS IS", with no warranties, and confers no
| rights.)
| --------------------
| | Thread-Topic: Optimistic concurrency in custom GridView/SqlDataSource
| | thread-index: AcXo/W8zDm9eKpv+TnG/WBTPf+bdaw==
| | X-WBNR-Posting-Host: 198.54.202.242
| | From: "=?Utf-8?B?TWlrZSBLZWxseQ==?=" <Mi*******@community.nospam>
| | References: <2F**********************************@microsoft.co m>
| <0c**************@TK2MSFTNGXA02.phx.gbl>
| <E0**********************************@microsoft.co m>
| <Hm**************@TK2MSFTNGXA02.phx.gbl>
| | Subject: RE: Optimistic concurrency in custom GridView/SqlDataSource
| | Date: Mon, 14 Nov 2005 01:26:04 -0800
| | Lines: 76
| | Message-ID: <7D**********************************@microsoft.co m>
| | MIME-Version: 1.0
| | Content-Type: text/plain;
| | charset="Utf-8"
| | Content-Transfer-Encoding: 7bit
| | X-Newsreader: Microsoft CDO for Windows 2000
| | Content-Class: urn:content-classes:message
| | Importance: normal
| | Priority: normal
| | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| | Newsgroups: microsoft.public.dotnet.framework.aspnet
| | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSF TNGXA03.phx.gbl
| | Xref: TK2MSFTNGXA02.phx.gbl
| microsoft.public.dotnet.framework.aspnet:357860
| | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| |
| | Here is a simple mockup page that models the problem.
| |
| | <%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs"
| | Inherits="_Default" %>
| |
| | <!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" DataKeyNames="id"
| | DataSourceID="SqlDataSourceOptimistic">
| | <Columns>
| | <asp:CommandField ShowEditButton="True" />
| | <asp:BoundField DataField="id" HeaderText="id"
| | InsertVisible="False" ReadOnly="True"
| | SortExpression="id" />
| | <asp:BoundField DataField="name" HeaderText="name"
| | SortExpression="name" />
| | </Columns>
| | </asp:GridView>
| | <asp:SqlDataSource ID="SqlDataSourceOptimistic" runat="server"
| | ConflictDetection="CompareAllValues"
| | ConnectionString="<%$
ConnectionStrings:PlayConnectionString
| %>"
| | DeleteCommand="DELETE FROM [Optimistic] WHERE [id] = @original_id AND
| [name]
| | = @original_name AND [rowversion] = @original_rowversion"
| | InsertCommand="INSERT INTO [Optimistic] ([name],
| [rowversion])
| | VALUES (@name, @rowversion)"
| | OldValuesParameterFormatString="original_{0}"
| | SelectCommand="SELECT * FROM [Optimistic]"
| | UpdateCommand="UPDATE [Optimistic] SET [name] = @name,
| | [rowversion] = @rowversion WHERE [id] = @original_id AND [name] =
| | @original_name AND [rowversion] = @original_rowversion">
| | <DeleteParameters>
| | <asp:Parameter Name="original_id" Type="Int32" />
| | <asp:Parameter Name="original_name" Type="String" />
| | <asp:Parameter Name="original_rowversion" Type="Object"
/>
| | </DeleteParameters>
| | <UpdateParameters>
| | <asp:Parameter Name="name" Type="String" />
| | <asp:Parameter Name="rowversion" Type="Object" />
| | <asp:Parameter Name="original_id" Type="Int32" />
| | <asp:Parameter Name="original_name" Type="String" />
| | <asp:Parameter Name="original_rowversion" Type="Object"
/>
| | </UpdateParameters>
| | <InsertParameters>
| | <asp:Parameter Name="name" Type="String" />
| | <asp:Parameter Name="rowversion" Type="Object" />
| | </InsertParameters>
| | </asp:SqlDataSource>
| |
| | </div>
| | </form>
| | </body>
| | </html>
| |
| | Here's the corresponding table:
| |
| | CREATE TABLE [dbo].[Optimistic](
| | [id] [int] IDENTITY(1,1) NOT NULL,
| | [name] [varchar](50) NULL,
| | [rowversion] [timestamp] NOT NULL,
| | CONSTRAINT [PK_Optimistic] PRIMARY KEY CLUSTERED
| | (
| | [id] ASC
| | )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
| | ) ON [PRIMARY]
| |
| | GO
| |
| |
|
|

Nov 20 '05 #7
Steven,

I am having the same problem as described throughout this thread. Could you
please reply with a solution to this problem of not being able to pass the
timestamp value back to sql server with the object data type?

"Steven Cheng[MSFT]" wrote:
Hi Mike,

I've just made some testing according to the code and database you
provided. Seems that the problem is somewhat related to the timestamp
sqltype's mapping in the .NET SqlDataSource control and GridView. From my
test, the SqlDataSource will mapp the timestamp column to an "Object" type
in DataSource's parameter, however, this type seem not able to persisted
the timestamp value. So when updating ,the value can not be actually passed
back to the SqlDataSource ... So I'm thinking that we may need to define
a custom template fields to store this timestamp value and manually adding
it into the updating parameter's collection through the GridView's updating
event...

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| X-Tomcat-ID: 299505317
| References: <2F**********************************@microsoft.co m>
<0c**************@TK2MSFTNGXA02.phx.gbl>
<E0**********************************@microsoft.co m>
<Hm**************@TK2MSFTNGXA02.phx.gbl>
<7D**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From: st*****@online.microsoft.com (Steven Cheng[MSFT])
| Organization: Microsoft
| Date: Tue, 15 Nov 2005 14:22:29 GMT
| Subject: RE: Optimistic concurrency in custom GridView/SqlDataSource
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| Message-ID: <F9**************@TK2MSFTNGXA02.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Lines: 118
| Path: TK2MSFTNGXA02.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:358233
| NNTP-Posting-Host: tomcatimport2.phx.gbl 10.201.218.182
|
| Thanks for your followup and the code, I'll make some tests and update
you
| soon.
|
| Thanks,
|
| Steven Cheng
| Microsoft Online Support
|
| Get Secure! www.microsoft.com/security
| (This posting is provided "AS IS", with no warranties, and confers no
| rights.)
| --------------------
| | Thread-Topic: Optimistic concurrency in custom GridView/SqlDataSource
| | thread-index: AcXo/W8zDm9eKpv+TnG/WBTPf+bdaw==
| | X-WBNR-Posting-Host: 198.54.202.242
| | From: "=?Utf-8?B?TWlrZSBLZWxseQ==?=" <Mi*******@community.nospam>
| | References: <2F**********************************@microsoft.co m>
| <0c**************@TK2MSFTNGXA02.phx.gbl>
| <E0**********************************@microsoft.co m>
| <Hm**************@TK2MSFTNGXA02.phx.gbl>
| | Subject: RE: Optimistic concurrency in custom GridView/SqlDataSource
| | Date: Mon, 14 Nov 2005 01:26:04 -0800
| | Lines: 76
| | Message-ID: <7D**********************************@microsoft.co m>
| | MIME-Version: 1.0
| | Content-Type: text/plain;
| | charset="Utf-8"
| | Content-Transfer-Encoding: 7bit
| | X-Newsreader: Microsoft CDO for Windows 2000
| | Content-Class: urn:content-classes:message
| | Importance: normal
| | Priority: normal
| | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| | Newsgroups: microsoft.public.dotnet.framework.aspnet
| | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSF TNGXA03.phx.gbl
| | Xref: TK2MSFTNGXA02.phx.gbl
| microsoft.public.dotnet.framework.aspnet:357860
| | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| |
| | Here is a simple mockup page that models the problem.
| |
| | <%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs"
| | Inherits="_Default" %>
| |
| | <!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" DataKeyNames="id"
| | DataSourceID="SqlDataSourceOptimistic">
| | <Columns>
| | <asp:CommandField ShowEditButton="True" />
| | <asp:BoundField DataField="id" HeaderText="id"
| | InsertVisible="False" ReadOnly="True"
| | SortExpression="id" />
| | <asp:BoundField DataField="name" HeaderText="name"
| | SortExpression="name" />
| | </Columns>
| | </asp:GridView>
| | <asp:SqlDataSource ID="SqlDataSourceOptimistic" runat="server"
| | ConflictDetection="CompareAllValues"
| | ConnectionString="<%$
ConnectionStrings:PlayConnectionString
| %>"
| | DeleteCommand="DELETE FROM [Optimistic] WHERE [id] = @original_id AND
| [name]
| | = @original_name AND [rowversion] = @original_rowversion"
| | InsertCommand="INSERT INTO [Optimistic] ([name],
| [rowversion])
| | VALUES (@name, @rowversion)"
| | OldValuesParameterFormatString="original_{0}"
| | SelectCommand="SELECT * FROM [Optimistic]"
| | UpdateCommand="UPDATE [Optimistic] SET [name] = @name,
| | [rowversion] = @rowversion WHERE [id] = @original_id AND [name] =
| | @original_name AND [rowversion] = @original_rowversion">
| | <DeleteParameters>
| | <asp:Parameter Name="original_id" Type="Int32" />
| | <asp:Parameter Name="original_name" Type="String" />
| | <asp:Parameter Name="original_rowversion" Type="Object"
/>
| | </DeleteParameters>
| | <UpdateParameters>
| | <asp:Parameter Name="name" Type="String" />
| | <asp:Parameter Name="rowversion" Type="Object" />
| | <asp:Parameter Name="original_id" Type="Int32" />
| | <asp:Parameter Name="original_name" Type="String" />
| | <asp:Parameter Name="original_rowversion" Type="Object"
/>
| | </UpdateParameters>
| | <InsertParameters>
| | <asp:Parameter Name="name" Type="String" />
| | <asp:Parameter Name="rowversion" Type="Object" />
| | </InsertParameters>
| | </asp:SqlDataSource>
| |
| | </div>
| | </form>
| | </body>
| | </html>
| |
| | Here's the corresponding table:
| |
| | CREATE TABLE [dbo].[Optimistic](
| | [id] [int] IDENTITY(1,1) NOT NULL,
| | [name] [varchar](50) NULL,
| | [rowversion] [timestamp] NOT NULL,
| | CONSTRAINT [PK_Optimistic] PRIMARY KEY CLUSTERED
| | (
| | [id] ASC
| | )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
| | ) ON [PRIMARY]
| |
| | GO
| |
| |
|
|

Dec 14 '05 #8
Hello Steven,

Thats a pretty poor show given the purpose of the timestamp. How it got
this far i'll never know, all i can say is you guys need to get some
application development done using microsoft technologies to see how the
real world copes. Sure you have your
ConflictDetection="CompareAllValues"

but come on - the sqlserver timestamp has for years on end been the way of
cicumventing that check. If it changed then the row changed. The only
reasons to use the full compareallvalues option would be to do the column
level conflict detection or to write more generic statements that would work
with more than one provider.

ok, so i've been using the beta .net 2 for some time now and now have the
final release. i waited for the finale to use this grid and sqldatasource
stuff thinking that by then you'd have it all ironed and the world would
have corrected you via the developer feedback site. i toyed with the
objectdatasource and the juries out on that one, reflection and all that
jazz. i kind of get the idea, your master plan, currently treading water in
the application developer domain, hoping soon to swim the 50m, but really
daft mistakes like this make us all sink.

silly ommisions that make the sqldatasource ridiculously code verbose defeat
the whole purpose of it. having to manually implement and workaround basic
concepts like timestamps really is a thumper. man i might as well just lay
down and let you roll a truck over me for all the good it does. this is .net
v2. sure you overhauled it - but am i gonna have to wait till 2.1 now to
get something decent? by then my applications will be so full of
workarounds it'll take a rewrite to sort it all out.

Cheers

Jason
"Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
news:xw*************@TK2MSFTNGXA02.phx.gbl...
Hi Mike,

I've just made some testing according to the code and database you
provided. Seems that the problem is somewhat related to the timestamp
sqltype's mapping in the .NET SqlDataSource control and GridView. From my
test, the SqlDataSource will mapp the timestamp column to an "Object" type
in DataSource's parameter, however, this type seem not able to persisted
the timestamp value. So when updating ,the value can not be actually
passed
back to the SqlDataSource ... So I'm thinking that we may need to
define
a custom template fields to store this timestamp value and manually adding
it into the updating parameter's collection through the GridView's
updating
event...

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| X-Tomcat-ID: 299505317
| References: <2F**********************************@microsoft.co m>
<0c**************@TK2MSFTNGXA02.phx.gbl>
<E0**********************************@microsoft.co m>
<Hm**************@TK2MSFTNGXA02.phx.gbl>
<7D**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From: st*****@online.microsoft.com (Steven Cheng[MSFT])
| Organization: Microsoft
| Date: Tue, 15 Nov 2005 14:22:29 GMT
| Subject: RE: Optimistic concurrency in custom GridView/SqlDataSource
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| Message-ID: <F9**************@TK2MSFTNGXA02.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Lines: 118
| Path: TK2MSFTNGXA02.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:358233
| NNTP-Posting-Host: tomcatimport2.phx.gbl 10.201.218.182
|
| Thanks for your followup and the code, I'll make some tests and update
you
| soon.
|
| Thanks,
|
| Steven Cheng
| Microsoft Online Support
|
| Get Secure! www.microsoft.com/security
| (This posting is provided "AS IS", with no warranties, and confers no
| rights.)
| --------------------
| | Thread-Topic: Optimistic concurrency in custom GridView/SqlDataSource
| | thread-index: AcXo/W8zDm9eKpv+TnG/WBTPf+bdaw==
| | X-WBNR-Posting-Host: 198.54.202.242
| | From: "=?Utf-8?B?TWlrZSBLZWxseQ==?=" <Mi*******@community.nospam>
| | References: <2F**********************************@microsoft.co m>
| <0c**************@TK2MSFTNGXA02.phx.gbl>
| <E0**********************************@microsoft.co m>
| <Hm**************@TK2MSFTNGXA02.phx.gbl>
| | Subject: RE: Optimistic concurrency in custom GridView/SqlDataSource
| | Date: Mon, 14 Nov 2005 01:26:04 -0800
| | Lines: 76
| | Message-ID: <7D**********************************@microsoft.co m>
| | MIME-Version: 1.0
| | Content-Type: text/plain;
| | charset="Utf-8"
| | Content-Transfer-Encoding: 7bit
| | X-Newsreader: Microsoft CDO for Windows 2000
| | Content-Class: urn:content-classes:message
| | Importance: normal
| | Priority: normal
| | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| | Newsgroups: microsoft.public.dotnet.framework.aspnet
| | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| | Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSF TNGXA03.phx.gbl
| | Xref: TK2MSFTNGXA02.phx.gbl
| microsoft.public.dotnet.framework.aspnet:357860
| | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| |
| | Here is a simple mockup page that models the problem.
| |
| | <%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs"
| | Inherits="_Default" %>
| |
| | <!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" DataKeyNames="id"
| | DataSourceID="SqlDataSourceOptimistic">
| | <Columns>
| | <asp:CommandField ShowEditButton="True" />
| | <asp:BoundField DataField="id" HeaderText="id"
| | InsertVisible="False" ReadOnly="True"
| | SortExpression="id" />
| | <asp:BoundField DataField="name" HeaderText="name"
| | SortExpression="name" />
| | </Columns>
| | </asp:GridView>
| | <asp:SqlDataSource ID="SqlDataSourceOptimistic" runat="server"
| | ConflictDetection="CompareAllValues"
| | ConnectionString="<%$
ConnectionStrings:PlayConnectionString
| %>"
| | DeleteCommand="DELETE FROM [Optimistic] WHERE [id] = @original_id AND
| [name]
| | = @original_name AND [rowversion] = @original_rowversion"
| | InsertCommand="INSERT INTO [Optimistic] ([name],
| [rowversion])
| | VALUES (@name, @rowversion)"
| | OldValuesParameterFormatString="original_{0}"
| | SelectCommand="SELECT * FROM [Optimistic]"
| | UpdateCommand="UPDATE [Optimistic] SET [name] = @name,
| | [rowversion] = @rowversion WHERE [id] = @original_id AND [name] =
| | @original_name AND [rowversion] = @original_rowversion">
| | <DeleteParameters>
| | <asp:Parameter Name="original_id" Type="Int32" />
| | <asp:Parameter Name="original_name" Type="String" />
| | <asp:Parameter Name="original_rowversion"
Type="Object"
/>
| | </DeleteParameters>
| | <UpdateParameters>
| | <asp:Parameter Name="name" Type="String" />
| | <asp:Parameter Name="rowversion" Type="Object" />
| | <asp:Parameter Name="original_id" Type="Int32" />
| | <asp:Parameter Name="original_name" Type="String" />
| | <asp:Parameter Name="original_rowversion"
Type="Object"
/>
| | </UpdateParameters>
| | <InsertParameters>
| | <asp:Parameter Name="name" Type="String" />
| | <asp:Parameter Name="rowversion" Type="Object" />
| | </InsertParameters>
| | </asp:SqlDataSource>
| |
| | </div>
| | </form>
| | </body>
| | </html>
| |
| | Here's the corresponding table:
| |
| | CREATE TABLE [dbo].[Optimistic](
| | [id] [int] IDENTITY(1,1) NOT NULL,
| | [name] [varchar](50) NULL,
| | [rowversion] [timestamp] NOT NULL,
| | CONSTRAINT [PK_Optimistic] PRIMARY KEY CLUSTERED
| | (
| | [id] ASC
| | )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
| | ) ON [PRIMARY]
| |
| | GO
| |
| |
|
|

Jan 4 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
2
by: John | last post by:
In 'Data Adapter Configuration Wizard' for OleDbDataAdapter, there's a checkbox called 'Use optimistic concurrency' that allows to turn on/off the option. I don't use the wizard, I create...
2
by: stuart.d.jones | last post by:
Hi, I'm using a detailsview control with an SqlDataSource control. My Update query isn't working, and I've narrowed it down to the optimistic concurrency parameters - i.e. when I comment them...
0
by: simonZ | last post by:
I created custom sql paging which returns always 10 rows of 1000. It has start page as input parameter. I have SQLdataSource and gridView. Affected rows by SQLdataSource is always 10 and because...
0
by: russganz | last post by:
It seems to me there are real problems with the datagridview (along with the detailsview and form view) control when using optimistic concurrency with fields that can be null. Trying to use these...
4
by: Andrew Robinson | last post by:
I am working on a system system that requires optimistic concurrency within a web app. At first I thought this would be easy. We generate our own entities and dal/service layer but I now see that...
1
by: =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post by:
(If I'm overlooking anything, please let me know.) First, my only concern is updating single records in a Detailsview using an ObjectDataSource. The target table has a timestamp field. Assume ...
4
by: mohaaron | last post by:
This seems like it should be simple to do but for some reason I have been unable to make it work. I would like to databind a SqlDataSource to a GridView during the click event of a button. This...
8
by: Roger.Noreply | last post by:
Hi, Sql-Server 2000, 2005. A report fetches a lot of rows using the "WITH (ROWLOCK)" syntax (the sql is generated on the fly by a tool and not easily changeable). SELECT col1, col2 FROM mytab...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.