Use Last-In-Wins Concurrency with the DataAdapter

Problem

You want to customize the DataAdapter update logic so that changes are allowed, even to records that have been modified by other users.

Solution

Customize the UpdateCommand so that is selects records based on a single unique field, instead of a combination of fields.

Discussion

The automatically generated update logic provided by the CommandBuilder selects records for an update by attempting to match each field in the WHERE clause. Here’s an example update command for the Shippers table from the Northwind database:

UPDATE Shippers SET CompanyName=[NewVal]
  WHERE ShipperID=[LastVal] AND CompanyName=[LastVal] AND Phone=[LastVal] ...

This approach is usually inefficient because it increases the amount ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.