dataadapter & dataset sychronization/Consistency

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have have database that I'd like to update a numerical field (field1).
However, I make changes to the dataset and then call the dataadapter.Update
function.
Here's the sequence
1. Get value in field1 (from dataset1)
2. field1 = field1 - variable1
3. Call dataadapter.Update(dataset1)
I am wondering if the possibility exist that if 2 users are updating field1
at the same time, then it might lead inconsistent data. If this is so, how
can I avoid this problem.
 
L.A. Jones,

This is definitely a possibility. This is why you use something like a
timestamp field or a date time field on your column. When you select the
data, you get the timestamp field.

Then, when you update your query, you update the row that corresponds to
the row that has the values. So, if you are using a primary key, you would
say "where key = <key>" to indicate the row to update. You would expand
that to say "where key = <key> and timestamp = <timestamp>". If no rows are
updated, then you know that someone beat you to it.

Here is a page in the MSDN documentation which talks about concurrency
in database operations:

http://msdn2.microsoft.com/en-us/library/aa0416cz.aspx

And here is another that explores using a primary key along with a
timestamp:

http://www.eggheadcafe.com/articles/20050719.asp

Hope this helps.
 
Thank you.
--
L. A. Jones


Nicholas Paldino said:
L.A. Jones,

This is definitely a possibility. This is why you use something like a
timestamp field or a date time field on your column. When you select the
data, you get the timestamp field.

Then, when you update your query, you update the row that corresponds to
the row that has the values. So, if you are using a primary key, you would
say "where key = <key>" to indicate the row to update. You would expand
that to say "where key = <key> and timestamp = <timestamp>". If no rows are
updated, then you know that someone beat you to it.

Here is a page in the MSDN documentation which talks about concurrency
in database operations:

http://msdn2.microsoft.com/en-us/library/aa0416cz.aspx

And here is another that explores using a primary key along with a
timestamp:

http://www.eggheadcafe.com/articles/20050719.asp

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Dave said:
I have have database that I'd like to update a numerical field (field1).
However, I make changes to the dataset and then call the
dataadapter.Update
function.
Here's the sequence
1. Get value in field1 (from dataset1)
2. field1 = field1 - variable1
3. Call dataadapter.Update(dataset1)
I am wondering if the possibility exist that if 2 users are updating
field1
at the same time, then it might lead inconsistent data. If this is so, how
can I avoid this problem.
 
Back
Top