This situation is known as data concurrency. If you expect that your users will be looking at/changing the same data you have to take this into account and write your application accordingly. If you use the .NET "wizards" to add data IO controls such as data adapters to your forms, it can construct update queries that use what is known as "pessimistic concurrency checks" on the updates. I'll explain in a simple example. Let's say we have a table "Users" with this structure:
Code:
UserID FirstName
====== =========
12 Nicolas
The key field on this table is UserID. Normally when you update this record, you use a query like this:
UPDATE Users SET FirstName='Peter' WHERE UserID=12
This is an optimistic update. You update it hoping that no one else has changed the FirstName field since you looked at it. The pessimistic update for this same record would look like this:
UPDATE Users SET FirstName='Peter' WHERE UserID=12 AND FirstName='Nicolas'
This query will only update the data if it hasn't changed since you looked at it. The ADO.NET DataTable keeps track of changes to rows and you can construct queries that have parameters tied to original values on changed rows. This allows for pessimistic updates that tell you if you can't update the row because of changed data.
-
Peter