473,383 Members | 1,863 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,383 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 2034

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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.