473,289 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Optimistic concurrency. I've found a ridiculously easy method.

(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 'Update <tableset blah = blah
Where (PK=@PK) and (ts=@ts)'. (Get rid of all that auto-generated 'original'
stuff. Also those IsNulls. They don't seem to serve any purpose except to
confuse. Don't use the Optimistic Concurrency option in the wizard.)

Get the record into the detailsview any way you see fit. I generally use
the first select statement to populate a grid and then call the detailsview
through a hyperlink. Then I create a 2nd select by PK.

Bind your detailsview. Here's the critical step. Add the timestamp field
to the DataKeyNames property of the detailsview (since the timestamp datatype
can't be passed any other way apparently.)

Next, add the following code to the Object Data Source Updating event
handler: e.InputParameters.Item("ts") = DetailsView1.DataKey.Item(1)

That's it. The only other thing you really have to do is check the
e.ReturnValue in the Object Data Source Updated. 1 is success, 0 is failure.
(For some reason the AffectedRows parameter is always returning -1)

Apparently if you use this sort of method, you are responsible for reporting
success or failure on the webpage. (Actually I was expecting a crash when I
tried to update an already updated record, but so much the better.)

One last question: Why have I not seen this in any tutorial?
Dec 18 '07 #1
1 2032

I think you've got a good tutorial, but I don't think you've discovered
anything new.

http://www.google.com/search?hl=en&q...2sql+server%22

http://davidhayden.com/blog/dave/arc...0/05/2503.aspx
Optimistic Concurrency Strategies
If you are in a performance state-of-mind, chances are you will go with
optimistic concurrency. Optimistic concurrency frees up database resources
as quickly as possible so that other users and processes can act upon that
data as soon as possible.

To the best of my knowledge, there are four popular strategies to dealing
with optimistic concurrency:

1.. Do Nothing.
2.. Check for changes to all fields during update.
3.. Check for changes to modified fields during update.
4.. Check for changes to timestamp ( rowversion ) during update.
I agree the N number of "OriginalThis" and "OriginalThat" is a pain is
overkill and ugly and non maintainable.

...

Start a blog, post your tutorial...then others can learn from your example.
Windows Live has free blog space.
http://sholliday.spaces.live.com/blog/

"B. Chernick" <BC*******@discussions.microsoft.comwrote in message
news:95**********************************@microsof t.com...
(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 'Update <tableset blah =
blah
Where (PK=@PK) and (ts=@ts)'. (Get rid of all that auto-generated
'original'
stuff. Also those IsNulls. They don't seem to serve any purpose except
to
confuse. Don't use the Optimistic Concurrency option in the wizard.)

Get the record into the detailsview any way you see fit. I generally use
the first select statement to populate a grid and then call the
detailsview
through a hyperlink. Then I create a 2nd select by PK.

Bind your detailsview. Here's the critical step. Add the timestamp field
to the DataKeyNames property of the detailsview (since the timestamp
datatype
can't be passed any other way apparently.)

Next, add the following code to the Object Data Source Updating event
handler: e.InputParameters.Item("ts") =
DetailsView1.DataKey.Item(1)

That's it. The only other thing you really have to do is check the
e.ReturnValue in the Object Data Source Updated. 1 is success, 0 is
failure.
(For some reason the AffectedRows parameter is always returning -1)

Apparently if you use this sort of method, you are responsible for
reporting
success or failure on the webpage. (Actually I was expecting a crash when
I
tried to update an already updated record, but so much the better.)

One last question: Why have I not seen this in any tutorial?

Dec 18 '07 #2

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

Similar topics

1
by: Chris Huddle | last post by:
Is there a way to turn off optimistic concurrency in ASP.NET when updating a record via the oleDBdataAdapter/oleDBcommandBuilder? If you use the Microsoft ASP.NET tools you can turn it off and...
8
by: Mike Kelly | last post by:
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...
2
by: John | last post by:
In 'Data Adapter Configuration Wizard' for OleDbDataAdapter, there's a checkbox called 'Use optimistic concurrency' that allows to turn on/off the option. I don't use the wizard, I create...
9
by: corey.coughlin | last post by:
Alright, so I've been following some of the arguments about enhancing parallelism in python, and I've kind of been struck by how hard things still are. It seems like what we really need is a more...
2
by: stuart.d.jones | last post by:
Hi, I'm using a detailsview control with an SqlDataSource control. My Update query isn't working, and I've narrowed it down to the optimistic concurrency parameters - i.e. when I comment them...
0
by: russganz | last post by:
It seems to me there are real problems with the datagridview (along with the detailsview and form view) control when using optimistic concurrency with fields that can be null. Trying to use these...
4
by: Andrew Robinson | last post by:
I am working on a system system that requires optimistic concurrency within a web app. At first I thought this would be easy. We generate our own entities and dal/service layer but I now see that...
1
by: =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post by:
I was suddenly told to whip up a web project in ASP.Net 2.0. The last few weeks have been a crash course in new technology. I've done some 1.1 web work but it's been a while. The basics are...
8
by: Roger.Noreply | last post by:
Hi, Sql-Server 2000, 2005. A report fetches a lot of rows using the "WITH (ROWLOCK)" syntax (the sql is generated on the fly by a tool and not easily changeable). SELECT col1, col2 FROM mytab...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.