473,573 Members | 2,865 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 "@RowVersio n"]
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="GridViewSha rePartners" runat="server"
AutoGenerateCol umns="False"
DataKeyNames="d bIDAntennaOwner ,dbIDSite"
DataSourceID="S harePartnerList " EmptyDataText=" No Partners on record for this
Site"
Width="549px"
OnRowEditing="G ridViewSharePar tners_RowEditin g" >
<Columns>
<asp:CommandFie ld ShowEditButton= "True" />
<asp:BoundFie ld DataField="dbID Site"
HeaderText="dbI DSite" ReadOnly="True" SortExpression= "dbIDSite"
Visible="False" />
<asp:BoundFie ld DataField="dbID AntennaOwner"
HeaderText="dbI DAntennaOwner" ReadOnly="True"
SortExpression= "dbIDAntennaOwn er" Visible="False" />
<asp:BoundFie ld DataField="Name " HeaderText="Nam e"
ReadOnly="True" SortExpression= "Name" />
<asp:BoundFie ld DataField="Part nerSiteID"
HeaderText="Par tnerSiteID" SortExpression= "PartnerSit eID" />
<asp:BoundFie ld DataField="Comm ents"
HeaderText="Com ments" SortExpression= "Comments" />
<asp:BoundFie ld DataField="RowV ersion"
HeaderText="Row Version" SortExpression= "RowVersion " ReadOnly="True"
Visible="False" />
</Columns>
<HeaderStyle HorizontalAlign ="Left" />
</asp:GridView>
<asp:SqlDataSou rce ID="SharePartne rList" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:VodacomEMRCo nnectionString %>"
SelectCommand=" SELECT * FROM vw_SharePartner WHERE
dbIDSite = @siteID"
UpdateCommand=" UPDATE SharePartner SET PartnerSiteID =
@PartnerSiteID, Comments = @Comments, UserName = @userName WHERE (dbIDSite =
@dbIDSite) AND (dbIDAntennaOwn er = @dbIDAntennaOwn er) ">
<UpdateParamete rs>
<asp:SessionPar ameter Name="userName"
SessionField="U serName" Type="String" />
<asp:QueryStrin gParameter Name="siteID"
QueryStringFiel d="siteID" Type="Int32" />
</UpdateParameter s>
<SelectParamete rs>
<asp:QueryStrin gParameter Name="siteID"
QueryStringFiel d="siteID" Type="Int32" />
</SelectParameter s>
</asp:SqlDataSour ce>

Nov 19 '05 #1
8 5023
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 (dbIDAntennaOwn er = @dbIDAntennaOwn er) ">

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 "@RowVersio n"]
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?TWlrZSBLZWx seQ==?=" <Mi*******@comm unity.nospam>
| Subject: Optimistic concurrency in custom GridView/SqlDataSource
| Date: Thu, 10 Nov 2005 00:56:02 -0800
| Lines: 64
| Message-ID: <2F************ *************** *******@microso ft.com>
| 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.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.p hx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGXA03.phx .gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3569 49
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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
"@RowVersio n"]
| 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="GridViewSha rePartners" runat="server"
| AutoGenerateCol umns="False"
| DataKeyNames="d bIDAntennaOwner ,dbIDSite"
| DataSourceID="S harePartnerList " EmptyDataText=" No Partners on record for
this
| Site"
| Width="549px"
| OnRowEditing="G ridViewSharePar tners_RowEditin g" >
| <Columns>
| <asp:CommandFie ld ShowEditButton= "True" />
| <asp:BoundFie ld DataField="dbID Site"
| HeaderText="dbI DSite" ReadOnly="True" SortExpression= "dbIDSite"
| Visible="False" />
| <asp:BoundFie ld DataField="dbID AntennaOwner"
| HeaderText="dbI DAntennaOwner" ReadOnly="True"
| SortExpression= "dbIDAntennaOwn er" Visible="False" />
| <asp:BoundFie ld DataField="Name "
HeaderText="Nam e"
| ReadOnly="True" SortExpression= "Name" />
| <asp:BoundFie ld DataField="Part nerSiteID"
| HeaderText="Par tnerSiteID" SortExpression= "PartnerSit eID" />
| <asp:BoundFie ld DataField="Comm ents"
| HeaderText="Com ments" SortExpression= "Comments" />
| <asp:BoundFie ld DataField="RowV ersion"
| HeaderText="Row Version" SortExpression= "RowVersion " ReadOnly="True"
| Visible="False" />
| </Columns>
| <HeaderStyle HorizontalAlign ="Left" />
| </asp:GridView>
| <asp:SqlDataSou rce ID="SharePartne rList" runat="server"
| ConnectionStrin g="<%$ ConnectionStrin gs:VodacomEMRCo nnectionString %>"
| SelectCommand=" SELECT * FROM vw_SharePartner WHERE
| dbIDSite = @siteID"
| UpdateCommand=" UPDATE SharePartner SET PartnerSiteID
=
| @PartnerSiteID, Comments = @Comments, UserName = @userName WHERE
(dbIDSite =
| @dbIDSite) AND (dbIDAntennaOwn er = @dbIDAntennaOwn er) ">
| <UpdateParamete rs>
| <asp:SessionPar ameter Name="userName"
| SessionField="U serName" Type="String" />
| <asp:QueryStrin gParameter Name="siteID"
| QueryStringFiel d="siteID" Type="Int32" />
| </UpdateParameter s>
| <SelectParamete rs>
| <asp:QueryStrin gParameter Name="siteID"
| QueryStringFiel d="siteID" Type="Int32" />
| </SelectParameter s>
| </asp:SqlDataSour ce>
|
|

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 (dbIDAntennaOwn er = @dbIDAntennaOwn er) 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 (dbIDAntennaOwn er = @dbIDAntennaOwn er) ">

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 "@RowVersio n"]
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?TWlrZSBLZWx seQ==?=" <Mi*******@comm unity.nospam>
| Subject: Optimistic concurrency in custom GridView/SqlDataSource
| Date: Thu, 10 Nov 2005 00:56:02 -0800
| Lines: 64
| Message-ID: <2F************ *************** *******@microso ft.com>
| 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.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.p hx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGXA03.phx .gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3569 49
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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
"@RowVersio n"]
| 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="GridViewSha rePartners" runat="server"
| AutoGenerateCol umns="False"
| DataKeyNames="d bIDAntennaOwner ,dbIDSite"
| DataSourceID="S harePartnerList " EmptyDataText=" No Partners on record for
this
| Site"
| Width="549px"
| OnRowEditing="G ridViewSharePar tners_RowEditin g" >
| <Columns>
| <asp:CommandFie ld ShowEditButton= "True" />
| <asp:BoundFie ld DataField="dbID Site"
| HeaderText="dbI DSite" ReadOnly="True" SortExpression= "dbIDSite"
| Visible="False" />
| <asp:BoundFie ld DataField="dbID AntennaOwner"
| HeaderText="dbI DAntennaOwner" ReadOnly="True"
| SortExpression= "dbIDAntennaOwn er" Visible="False" />
| <asp:BoundFie ld DataField="Name "
HeaderText="Nam e"
| ReadOnly="True" SortExpression= "Name" />
| <asp:BoundFie ld DataField="Part nerSiteID"
| HeaderText="Par tnerSiteID" SortExpression= "PartnerSit eID" />
| <asp:BoundFie ld DataField="Comm ents"
| HeaderText="Com ments" SortExpression= "Comments" />
| <asp:BoundFie ld DataField="RowV ersion"
| HeaderText="Row Version" SortExpression= "RowVersion " ReadOnly="True"
| Visible="False" />
| </Columns>
| <HeaderStyle HorizontalAlign ="Left" />
| </asp:GridView>
| <asp:SqlDataSou rce ID="SharePartne rList" runat="server"
| ConnectionStrin g="<%$ ConnectionStrin gs:VodacomEMRCo nnectionString %>"
| SelectCommand=" SELECT * FROM vw_SharePartner WHERE
| dbIDSite = @siteID"
| UpdateCommand=" UPDATE SharePartner SET PartnerSiteID
=
| @PartnerSiteID, Comments = @Comments, UserName = @userName WHERE
(dbIDSite =
| @dbIDSite) AND (dbIDAntennaOwn er = @dbIDAntennaOwn er) ">
| <UpdateParamete rs>
| <asp:SessionPar ameter Name="userName"
| SessionField="U serName" Type="String" />
| <asp:QueryStrin gParameter Name="siteID"
| QueryStringFiel d="siteID" Type="Int32" />
| </UpdateParameter s>
| <SelectParamete rs>
| <asp:QueryStrin gParameter Name="siteID"
| QueryStringFiel d="siteID" Type="Int32" />
| </SelectParameter s>
| </asp:SqlDataSour ce>
|
|

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

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: AcXmkkn3ShM1FjC rR9uiEzCRTh5HhQ ==
| X-WBNR-Posting-Host: 198.54.202.242
| From: "=?Utf-8?B?TWlrZSBLZWx seQ==?=" <Mi*******@comm unity.nospam>
| References: <2F************ *************** *******@microso ft.com>
<0c************ **@TK2MSFTNGXA0 2.phx.gbl>
| Subject: RE: Optimistic concurrency in custom GridView/SqlDataSource
| Date: Thu, 10 Nov 2005 23:34:03 -0800
| Lines: 154
| Message-ID: <E0************ *************** *******@microso ft.com>
| 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.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.p hx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GXA03.phx.gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3572 93
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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 (dbIDAntennaOwn er = @dbIDAntennaOwn er) 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 (dbIDAntennaOwn er = @dbIDAntennaOwn er) ">
| >
| > 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 "@RowVersio n"]
| > 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?TWlrZSBLZWx seQ==?=" <Mi*******@comm unity.nospam>
| > | Subject: Optimistic concurrency in custom GridView/SqlDataSource
| > | Date: Thu, 10 Nov 2005 00:56:02 -0800
| > | Lines: 64
| > | Message-ID: <2F************ *************** *******@microso ft.com>
| > | 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.publi c.dotnet.framew ork.aspnet
| > | NNTP-Posting-Host: TK2MSFTNGXA03.p hx.gbl 10.40.2.250
| > | Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGXA03.phx .gbl
| > | Xref: TK2MSFTNGXA02.p hx.gbl
| > microsoft.publi c.dotnet.framew ork.aspnet:3569 49
| > | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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
| > "@RowVersio n"]
| > | 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="GridViewSha rePartners"
runat="server"
| > | AutoGenerateCol umns="False"
| > | DataKeyNames="d bIDAntennaOwner ,dbIDSite"
| > | DataSourceID="S harePartnerList " EmptyDataText=" No Partners on record
for
| > this
| > | Site"
| > | Width="549px"
| > | OnRowEditing="G ridViewSharePar tners_RowEditin g" >
| > | <Columns>
| > | <asp:CommandFie ld ShowEditButton= "True" />
| > | <asp:BoundFie ld DataField="dbID Site"
| > | HeaderText="dbI DSite" ReadOnly="True" SortExpression= "dbIDSite"
| > | Visible="False" />
| > | <asp:BoundFie ld DataField="dbID AntennaOwner"
| > | HeaderText="dbI DAntennaOwner" ReadOnly="True"
| > | SortExpression= "dbIDAntennaOwn er" Visible="False" />
| > | <asp:BoundFie ld DataField="Name "
| > HeaderText="Nam e"
| > | ReadOnly="True" SortExpression= "Name" />
| > | <asp:BoundFie ld DataField="Part nerSiteID"
| > | HeaderText="Par tnerSiteID" SortExpression= "PartnerSit eID" />
| > | <asp:BoundFie ld DataField="Comm ents"
| > | HeaderText="Com ments" SortExpression= "Comments" />
| > | <asp:BoundFie ld DataField="RowV ersion"
| > | HeaderText="Row Version" SortExpression= "RowVersion " ReadOnly="True"
| > | Visible="False" />
| > | </Columns>
| > | <HeaderStyle HorizontalAlign ="Left" />
| > | </asp:GridView>
| > | <asp:SqlDataSou rce ID="SharePartne rList"
runat="server"
| > | ConnectionStrin g="<%$ ConnectionStrin gs:VodacomEMRCo nnectionString
%>"
| > | SelectCommand=" SELECT * FROM vw_SharePartner
WHERE
| > | dbIDSite = @siteID"
| > | UpdateCommand=" UPDATE SharePartner SET
PartnerSiteID
| > =
| > | @PartnerSiteID, Comments = @Comments, UserName = @userName WHERE
| > (dbIDSite =
| > | @dbIDSite) AND (dbIDAntennaOwn er = @dbIDAntennaOwn er) ">
| > | <UpdateParamete rs>
| > | <asp:SessionPar ameter Name="userName"
| > | SessionField="U serName" Type="String" />
| > | <asp:QueryStrin gParameter Name="siteID"
| > | QueryStringFiel d="siteID" Type="Int32" />
| > | </UpdateParameter s>
| > | <SelectParamete rs>
| > | <asp:QueryStrin gParameter Name="siteID"
| > | QueryStringFiel d="siteID" Type="Int32" />
| > | </SelectParameter s>
| > | </asp:SqlDataSour ce>
| > |
| > |
| >
| >
|

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

<%@ Page Language="C#" AutoEventWireup ="true" CodeFile="Defau lt.aspx.cs"
Inherits="_Defa ult" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateCol umns="False" DataKeyNames="i d"
DataSourceID="S qlDataSourceOpt imistic">
<Columns>
<asp:CommandFie ld ShowEditButton= "True" />
<asp:BoundFie ld DataField="id" HeaderText="id"
InsertVisible=" False" ReadOnly="True"
SortExpression= "id" />
<asp:BoundFie ld DataField="name " HeaderText="nam e"
SortExpression= "name" />
</Columns>
</asp:GridView>
<asp:SqlDataSou rce ID="SqlDataSour ceOptimistic" runat="server"
ConflictDetecti on="CompareAllV alues"
ConnectionStrin g="<%$ ConnectionStrin gs:PlayConnecti onString %>"
DeleteCommand=" DELETE FROM [Optimistic] WHERE [id] = @original_id AND [name]
= @original_name AND [rowversion] = @original_rowve rsion"
InsertCommand=" INSERT INTO [Optimistic] ([name], [rowversion])
VALUES (@name, @rowversion)"
OldValuesParame terFormatString ="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_rowve rsion">
<DeleteParamete rs>
<asp:Paramete r Name="original_ id" Type="Int32" />
<asp:Paramete r Name="original_ name" Type="String" />
<asp:Paramete r Name="original_ rowversion" Type="Object" />
</DeleteParameter s>
<UpdateParamete rs>
<asp:Paramete r Name="name" Type="String" />
<asp:Paramete r Name="rowversio n" Type="Object" />
<asp:Paramete r Name="original_ id" Type="Int32" />
<asp:Paramete r Name="original_ name" Type="String" />
<asp:Paramete r Name="original_ rowversion" Type="Object" />
</UpdateParameter s>
<InsertParamete rs>
<asp:Paramete r Name="name" Type="String" />
<asp:Paramete r Name="rowversio n" Type="Object" />
</InsertParameter s>
</asp:SqlDataSour ce>

</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?TWlrZSBLZWx seQ==?=" <Mi*******@comm unity.nospam>
| References: <2F************ *************** *******@microso ft.com>
<0c************ **@TK2MSFTNGXA0 2.phx.gbl>
<E0************ *************** *******@microso ft.com>
<Hm************ **@TK2MSFTNGXA0 2.phx.gbl>
| Subject: RE: Optimistic concurrency in custom GridView/SqlDataSource
| Date: Mon, 14 Nov 2005 01:26:04 -0800
| Lines: 76
| Message-ID: <7D************ *************** *******@microso ft.com>
| 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.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.p hx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GXA01.phx.gbl!T K2MSFTNGXA03.ph x.gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3578 60
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| Here is a simple mockup page that models the problem.
|
| <%@ Page Language="C#" AutoEventWireup ="true" CodeFile="Defau lt.aspx.cs"
| Inherits="_Defa ult" %>
|
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
| "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
|
| <html xmlns="http://www.w3.org/1999/xhtml" >
| <head runat="server">
| <title>Untitl ed Page</title>
| </head>
| <body>
| <form id="form1" runat="server">
| <div>
| <asp:GridView ID="GridView1" runat="server"
| AutoGenerateCol umns="False" DataKeyNames="i d"
| DataSourceID="S qlDataSourceOpt imistic">
| <Columns>
| <asp:CommandFie ld ShowEditButton= "True" />
| <asp:BoundFie ld DataField="id" HeaderText="id"
| InsertVisible=" False" ReadOnly="True"
| SortExpression= "id" />
| <asp:BoundFie ld DataField="name " HeaderText="nam e"
| SortExpression= "name" />
| </Columns>
| </asp:GridView>
| <asp:SqlDataSou rce ID="SqlDataSour ceOptimistic" runat="server"
| ConflictDetecti on="CompareAllV alues"
| ConnectionStrin g="<%$ ConnectionStrin gs:PlayConnecti onString
%>"
| DeleteCommand=" DELETE FROM [Optimistic] WHERE [id] = @original_id AND
[name]
| = @original_name AND [rowversion] = @original_rowve rsion"
| InsertCommand=" INSERT INTO [Optimistic] ([name],
[rowversion])
| VALUES (@name, @rowversion)"
| OldValuesParame terFormatString ="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_rowve rsion">
| <DeleteParamete rs>
| <asp:Paramete r Name="original_ id" Type="Int32" />
| <asp:Paramete r Name="original_ name" Type="String" />
| <asp:Paramete r Name="original_ rowversion" Type="Object" />
| </DeleteParameter s>
| <UpdateParamete rs>
| <asp:Paramete r Name="name" Type="String" />
| <asp:Paramete r Name="rowversio n" Type="Object" />
| <asp:Paramete r Name="original_ id" Type="Int32" />
| <asp:Paramete r Name="original_ name" Type="String" />
| <asp:Paramete r Name="original_ rowversion" Type="Object" />
| </UpdateParameter s>
| <InsertParamete rs>
| <asp:Paramete r Name="name" Type="String" />
| <asp:Paramete r Name="rowversio n" Type="Object" />
| </InsertParameter s>
| </asp:SqlDataSour ce>
|
| </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************ *************** *******@microso ft.com>
<0c************ **@TK2MSFTNGXA0 2.phx.gbl>
<E0************ *************** *******@microso ft.com>
<Hm************ **@TK2MSFTNGXA0 2.phx.gbl>
<7D************ *************** *******@microso ft.com>
| 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.publi c.dotnet.framew ork.aspnet
| Message-ID: <F9************ **@TK2MSFTNGXA0 2.phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| Lines: 118
| Path: TK2MSFTNGXA02.p hx.gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3582 33
| NNTP-Posting-Host: tomcatimport2.p hx.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?TWlrZSBLZWx seQ==?=" <Mi*******@comm unity.nospam>
| | References: <2F************ *************** *******@microso ft.com>
| <0c************ **@TK2MSFTNGXA0 2.phx.gbl>
| <E0************ *************** *******@microso ft.com>
| <Hm************ **@TK2MSFTNGXA0 2.phx.gbl>
| | Subject: RE: Optimistic concurrency in custom GridView/SqlDataSource
| | Date: Mon, 14 Nov 2005 01:26:04 -0800
| | Lines: 76
| | Message-ID: <7D************ *************** *******@microso ft.com>
| | 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.publi c.dotnet.framew ork.aspnet
| | NNTP-Posting-Host: TK2MSFTNGXA03.p hx.gbl 10.40.2.250
| | Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GXA01.phx.gbl!T K2MSFTNGXA03.ph x.gbl
| | Xref: TK2MSFTNGXA02.p hx.gbl
| microsoft.publi c.dotnet.framew ork.aspnet:3578 60
| | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| |
| | Here is a simple mockup page that models the problem.
| |
| | <%@ Page Language="C#" AutoEventWireup ="true"
CodeFile="Defau lt.aspx.cs"
| | Inherits="_Defa ult" %>
| |
| | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
| | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
| |
| | <html xmlns="http://www.w3.org/1999/xhtml" >
| | <head runat="server">
| | <title>Untitl ed Page</title>
| | </head>
| | <body>
| | <form id="form1" runat="server">
| | <div>
| | <asp:GridView ID="GridView1" runat="server"
| | AutoGenerateCol umns="False" DataKeyNames="i d"
| | DataSourceID="S qlDataSourceOpt imistic">
| | <Columns>
| | <asp:CommandFie ld ShowEditButton= "True" />
| | <asp:BoundFie ld DataField="id" HeaderText="id"
| | InsertVisible=" False" ReadOnly="True"
| | SortExpression= "id" />
| | <asp:BoundFie ld DataField="name " HeaderText="nam e"
| | SortExpression= "name" />
| | </Columns>
| | </asp:GridView>
| | <asp:SqlDataSou rce ID="SqlDataSour ceOptimistic" runat="server"
| | ConflictDetecti on="CompareAllV alues"
| | ConnectionStrin g="<%$
ConnectionStrin gs:PlayConnecti onString
| %>"
| | DeleteCommand=" DELETE FROM [Optimistic] WHERE [id] = @original_id AND
| [name]
| | = @original_name AND [rowversion] = @original_rowve rsion"
| | InsertCommand=" INSERT INTO [Optimistic] ([name],
| [rowversion])
| | VALUES (@name, @rowversion)"
| | OldValuesParame terFormatString ="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_rowve rsion">
| | <DeleteParamete rs>
| | <asp:Paramete r Name="original_ id" Type="Int32" />
| | <asp:Paramete r Name="original_ name" Type="String" />
| | <asp:Paramete r Name="original_ rowversion" Type="Object"
/>
| | </DeleteParameter s>
| | <UpdateParamete rs>
| | <asp:Paramete r Name="name" Type="String" />
| | <asp:Paramete r Name="rowversio n" Type="Object" />
| | <asp:Paramete r Name="original_ id" Type="Int32" />
| | <asp:Paramete r Name="original_ name" Type="String" />
| | <asp:Paramete r Name="original_ rowversion" Type="Object"
/>
| | </UpdateParameter s>
| | <InsertParamete rs>
| | <asp:Paramete r Name="name" Type="String" />
| | <asp:Paramete r Name="rowversio n" Type="Object" />
| | </InsertParameter s>
| | </asp:SqlDataSour ce>
| |
| | </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************ *************** *******@microso ft.com>
<0c************ **@TK2MSFTNGXA0 2.phx.gbl>
<E0************ *************** *******@microso ft.com>
<Hm************ **@TK2MSFTNGXA0 2.phx.gbl>
<7D************ *************** *******@microso ft.com>
| 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.publi c.dotnet.framew ork.aspnet
| Message-ID: <F9************ **@TK2MSFTNGXA0 2.phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| Lines: 118
| Path: TK2MSFTNGXA02.p hx.gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3582 33
| NNTP-Posting-Host: tomcatimport2.p hx.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?TWlrZSBLZWx seQ==?=" <Mi*******@comm unity.nospam>
| | References: <2F************ *************** *******@microso ft.com>
| <0c************ **@TK2MSFTNGXA0 2.phx.gbl>
| <E0************ *************** *******@microso ft.com>
| <Hm************ **@TK2MSFTNGXA0 2.phx.gbl>
| | Subject: RE: Optimistic concurrency in custom GridView/SqlDataSource
| | Date: Mon, 14 Nov 2005 01:26:04 -0800
| | Lines: 76
| | Message-ID: <7D************ *************** *******@microso ft.com>
| | 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.publi c.dotnet.framew ork.aspnet
| | NNTP-Posting-Host: TK2MSFTNGXA03.p hx.gbl 10.40.2.250
| | Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GXA01.phx.gbl!T K2MSFTNGXA03.ph x.gbl
| | Xref: TK2MSFTNGXA02.p hx.gbl
| microsoft.publi c.dotnet.framew ork.aspnet:3578 60
| | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| |
| | Here is a simple mockup page that models the problem.
| |
| | <%@ Page Language="C#" AutoEventWireup ="true"
CodeFile="Defau lt.aspx.cs"
| | Inherits="_Defa ult" %>
| |
| | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
| | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
| |
| | <html xmlns="http://www.w3.org/1999/xhtml" >
| | <head runat="server">
| | <title>Untitl ed Page</title>
| | </head>
| | <body>
| | <form id="form1" runat="server">
| | <div>
| | <asp:GridView ID="GridView1" runat="server"
| | AutoGenerateCol umns="False" DataKeyNames="i d"
| | DataSourceID="S qlDataSourceOpt imistic">
| | <Columns>
| | <asp:CommandFie ld ShowEditButton= "True" />
| | <asp:BoundFie ld DataField="id" HeaderText="id"
| | InsertVisible=" False" ReadOnly="True"
| | SortExpression= "id" />
| | <asp:BoundFie ld DataField="name " HeaderText="nam e"
| | SortExpression= "name" />
| | </Columns>
| | </asp:GridView>
| | <asp:SqlDataSou rce ID="SqlDataSour ceOptimistic" runat="server"
| | ConflictDetecti on="CompareAllV alues"
| | ConnectionStrin g="<%$
ConnectionStrin gs:PlayConnecti onString
| %>"
| | DeleteCommand=" DELETE FROM [Optimistic] WHERE [id] = @original_id AND
| [name]
| | = @original_name AND [rowversion] = @original_rowve rsion"
| | InsertCommand=" INSERT INTO [Optimistic] ([name],
| [rowversion])
| | VALUES (@name, @rowversion)"
| | OldValuesParame terFormatString ="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_rowve rsion">
| | <DeleteParamete rs>
| | <asp:Paramete r Name="original_ id" Type="Int32" />
| | <asp:Paramete r Name="original_ name" Type="String" />
| | <asp:Paramete r Name="original_ rowversion" Type="Object"
/>
| | </DeleteParameter s>
| | <UpdateParamete rs>
| | <asp:Paramete r Name="name" Type="String" />
| | <asp:Paramete r Name="rowversio n" Type="Object" />
| | <asp:Paramete r Name="original_ id" Type="Int32" />
| | <asp:Paramete r Name="original_ name" Type="String" />
| | <asp:Paramete r Name="original_ rowversion" Type="Object"
/>
| | </UpdateParameter s>
| | <InsertParamete rs>
| | <asp:Paramete r Name="name" Type="String" />
| | <asp:Paramete r Name="rowversio n" Type="Object" />
| | </InsertParameter s>
| | </asp:SqlDataSour ce>
| |
| | </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
ConflictDetecti on="CompareAllV alues"

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 compareallvalue s 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
objectdatasourc e 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******** *****@TK2MSFTNG XA02.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************ *************** *******@microso ft.com>
<0c************ **@TK2MSFTNGXA0 2.phx.gbl>
<E0************ *************** *******@microso ft.com>
<Hm************ **@TK2MSFTNGXA0 2.phx.gbl>
<7D************ *************** *******@microso ft.com>
| 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.publi c.dotnet.framew ork.aspnet
| Message-ID: <F9************ **@TK2MSFTNGXA0 2.phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| Lines: 118
| Path: TK2MSFTNGXA02.p hx.gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3582 33
| NNTP-Posting-Host: tomcatimport2.p hx.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?TWlrZSBLZWx seQ==?=" <Mi*******@comm unity.nospam>
| | References: <2F************ *************** *******@microso ft.com>
| <0c************ **@TK2MSFTNGXA0 2.phx.gbl>
| <E0************ *************** *******@microso ft.com>
| <Hm************ **@TK2MSFTNGXA0 2.phx.gbl>
| | Subject: RE: Optimistic concurrency in custom GridView/SqlDataSource
| | Date: Mon, 14 Nov 2005 01:26:04 -0800
| | Lines: 76
| | Message-ID: <7D************ *************** *******@microso ft.com>
| | 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.publi c.dotnet.framew ork.aspnet
| | NNTP-Posting-Host: TK2MSFTNGXA03.p hx.gbl 10.40.2.250
| | Path:
TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GXA01.phx.gbl!T K2MSFTNGXA03.ph x.gbl
| | Xref: TK2MSFTNGXA02.p hx.gbl
| microsoft.publi c.dotnet.framew ork.aspnet:3578 60
| | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| |
| | Here is a simple mockup page that models the problem.
| |
| | <%@ Page Language="C#" AutoEventWireup ="true"
CodeFile="Defau lt.aspx.cs"
| | Inherits="_Defa ult" %>
| |
| | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
| | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
| |
| | <html xmlns="http://www.w3.org/1999/xhtml" >
| | <head runat="server">
| | <title>Untitl ed Page</title>
| | </head>
| | <body>
| | <form id="form1" runat="server">
| | <div>
| | <asp:GridView ID="GridView1" runat="server"
| | AutoGenerateCol umns="False" DataKeyNames="i d"
| | DataSourceID="S qlDataSourceOpt imistic">
| | <Columns>
| | <asp:CommandFie ld ShowEditButton= "True" />
| | <asp:BoundFie ld DataField="id" HeaderText="id"
| | InsertVisible=" False" ReadOnly="True"
| | SortExpression= "id" />
| | <asp:BoundFie ld DataField="name " HeaderText="nam e"
| | SortExpression= "name" />
| | </Columns>
| | </asp:GridView>
| | <asp:SqlDataSou rce ID="SqlDataSour ceOptimistic" runat="server"
| | ConflictDetecti on="CompareAllV alues"
| | ConnectionStrin g="<%$
ConnectionStrin gs:PlayConnecti onString
| %>"
| | DeleteCommand=" DELETE FROM [Optimistic] WHERE [id] = @original_id AND
| [name]
| | = @original_name AND [rowversion] = @original_rowve rsion"
| | InsertCommand=" INSERT INTO [Optimistic] ([name],
| [rowversion])
| | VALUES (@name, @rowversion)"
| | OldValuesParame terFormatString ="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_rowve rsion">
| | <DeleteParamete rs>
| | <asp:Paramete r Name="original_ id" Type="Int32" />
| | <asp:Paramete r Name="original_ name" Type="String" />
| | <asp:Paramete r Name="original_ rowversion"
Type="Object"
/>
| | </DeleteParameter s>
| | <UpdateParamete rs>
| | <asp:Paramete r Name="name" Type="String" />
| | <asp:Paramete r Name="rowversio n" Type="Object" />
| | <asp:Paramete r Name="original_ id" Type="Int32" />
| | <asp:Paramete r Name="original_ name" Type="String" />
| | <asp:Paramete r Name="original_ rowversion"
Type="Object"
/>
| | </UpdateParameter s>
| | <InsertParamete rs>
| | <asp:Paramete r Name="name" Type="String" />
| | <asp:Paramete r Name="rowversio n" Type="Object" />
| | </InsertParameter s>
| | </asp:SqlDataSour ce>
| |
| | </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
14791
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 want to look at that data and filter it based on what is in it. I know that this could have been done with data sets and data views in asp.net 1.1...
2
2188
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 MyDataAdapter using the following, MyDataAdapter = new New OleDbDataAdapter(MySql, MyDatabase) The question is how to turn off the 'Use optimistic...
2
1582
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 out of the query, it works. What seems to be happening is that if a field is NULL when it is read in through the select statement, it's causing the...
0
924
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 of that gridView doesn't show the right number of pages. How can I set that paging on GridView will show 100 pages instead of 1 page. Can I...
0
1560
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 controls I have many times had the update not work with no error generated. After much experimentation I have narrowed it down to how the Update...
4
1569
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 working with controls like a grid view pose some very complicated issues. If I am using rowversion, when do I start the "clock"? When I first...
1
2045
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 a single primary key. Create your xsd. Drag the table onto the xsd. Then manually edit the Update statement to simplify it. Essentially...
4
9773
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 sounds easy but the next requirement is that the GridView is editable. So I have included the SelectCommand and the UpdateCommand on the...
8
3967
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 WITH (ROWLOCK) WHERE ...." The select-clause runs for several minutes. Another user fetches one of those rows and tries to update it. The result...
0
7755
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7992
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7756
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6385
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5281
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3722
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3722
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2183
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1284
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.