Updating database from multiple application

  • Thread starter Thread starter seban
  • Start date Start date
S

seban

Hi All
I have a multi user application.I am populating the data to a datagrid from
a dataset.If i had made the changes on it. I am updating it by using the
datatsets getchanges and sqldataadapters update methods.

Suppose 2 users say A and B opened the application in their respective
machines at the same time.Suppose A edited a column of a record and saved
successfully.But the user B didn't get to know this change that had occurred
and he is having the old data from the DB.Suppose user B edited another
column of the same record that user A has edited and when he updates it
calls the getchanges method of the dataset which contains old record and
when he updates, the same record is updated with the old values and only the
column that B edited has changed.The change made by A is updated back with
old value.How I can solve this !!!!!11


Thanks in advance
Seban
 
This is called optimistic concurrency. many ways to check for this. Easiest
is with a timestamp.

If the timestamps differ on an update, you know the record has been updated
since you selected it. Its a business decision on how to handle this.
Typically, you will let the user know that the values are different and ask
them what they want to do.
 
With each record in your database table, keep a timestamp column (sql
provides this type for you). Now, on each update, reset the timestamp (sql
server will do this for you). On each select, make sure your select the
timestamp column. On each update, make sure you compare the timestamp
column values. If the client's differs from the servers', the record has
been changed since the last time you touched it.
 
what about the sql update/insert/delete statements that the
commandbuilder generate? they comapre the original values in the
dataSet with the values on the database.. i suppose that's optimistic
concurrency as well.. although that's a lot more comparisons than the
timestamp...
 
Back
Top