You have two excellent responses so far.
I just want to add one thing:
SQL Server has a column called a timestamp. It's an odd name, because it
does NOT store a datetime value. It stores a number that is automatically
updated to a clock count on the SQL Server EVERY time your row is updated.
If you have a table that you suspect a large number of people may be
updating, you will want to put a timestamp column into the table. That way,
you can select any row you want, update the data in your fields, and before
you update the row in the database, check to see if the timestamp column has
been changed. If it has changed, then someone else updated the same row,
and you should fail the update.
This may seem onerous. A user updates fields in a database row, clicks
Update, and gets an error message. If the collisions are rare, this isn't a
problem. In the past, I would have the Data Layer automatically select the
updated row, and my U/I layer would compare the fields between the data row
and the visible fields. If there is a difference, a window would appear
showing the values from the database along with an error explaining the
issue. The user could choose to overwrite the other person's changes,
whereupon the U/I would overwrite values into the data layer and call
..Update again, or the user would accept the differences. If there are no
differences (in other words, if two users made the exact same update at the
exact same time... it could happen), then I don't issue an error message.
As one of the other responders pointed out, the SQL generated by the data
adapter will automatically check every field (you can turn this off in the
data adapter wizard if you want). You can update that SQL to tell it to
only check the timestamp column, assuming you have added one.
If you have a high liklihood that two users will try to update the same row,
then I'd suggest adding a little "workflow" to your application. A user has
to indicate that they want to edit the row. When they do, your app calls a
stored proc with the user id as a parameter, and you store the userid in the
row to indicate that it is Checked Out (remember to check the timestamp to
make sure someone else didn't already check it out!). If another user has
checked it out, put an unobtrusive message or indication in your form and
you user will move on. If not, your user gets the record and an edit form
appears. This way, you can be fairly sure that no one else is editing the
row at the same time. You still need to check the timestamp when you store
updates, but you will get very very few hits, if any. (that would be an
interesting test case for your code, though).
Also, this way, you can have the row "remember" the id of the last user to
modify it, or you can keep a log of users who have checked out the row as
records in an associated table... lots of useful things.
I hope this helps.
Good Luck,
--- Nick
"Tc" <Tc@bloat.net > wrote in message
news:ui******** **************@ news.easynews.c om...
Hi,
I was curious, I am thinking of writing an application that loads a
dataset from a database that resides on a server. The question I have is this, if
multiple copies of the app will be running at once will there be problems
with data updates?
The reason I ask is I'm thinking like this:
User1 launches the app and the dataset is created from the data in the DB.
User2 does the same.
User1 updates row 9 in the db and the information is saved.
User2 updates row 100 in the db and saves the changes.
Does row 9 from User2 (the original row 9) replace the changes that User1
made? or will only the specific changes in that dataset be posted back to
the server?
As you can tell I'm new at this and a bit confused.
Thank you very much..