By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,606 Members | 2,019 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,606 IT Pros & Developers. It's quick & easy.

Optimistic concurrency in custom GridView/SqlDataSource

P: n/a
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
Share this Question
Share on Google+
8 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.