Merge PreserveChanges = False not working -- need help



I have been chasing my tail and need some help from someone who has
succeeded in real-world-handling (i.e. not merely detecting) a
concurrency violation in ADO.NET with SQL Server back-end.

My data layer class invokes the DataAdapter.Update method and traps
concurrency violations as a DBConcurrencyException, as follows:
Catch DBEX As System.Data.DBConcurrencyException
'// read the 'fresh' row from the DB
Dim Fresh As DataTable = SelectSingle(ID)

'// at this point, Fresh contains the most recent version of the row

'// merge it with the disconnected dataset
DS.Merge(Fresh, False, MissingSchemaAction.Ignore)

In the exception handler, the fresh version of the row is selected from
the database, and then merged into the dataset. The intention is to
replace the stale values in the dataset with fresh values from the
database. Therefore, the PreserveChanges second parameter is set to False.

However, this never works. As I step through the code in the debugger,
Fresh does have the data as changed by another user, which is good. But
after the merge the Dataset (DS) always retains the stale copy of the
row. The merge is not overwriting the stale values with the fresh values
from the database.

I've tried changing the second parameter of the Merge method to True,
but the results are the same, thinking it was perhaps a documentation
bug. No luck.

What am I doing wrong?


My user wants to merge her desired changes with those made by another
user a minute ago after my user had read the record. How do you properly
clear the error condition which is visible in the OnRowUpdated method of
the DataAdapter? If I set e.Status= Continue (or to SkipCurrentRow) then
no System.Data.DBConcurrencyException is raised in the routine where
the DataAdapter's update method is invoked. :-(

I would be very grateful if someone could point me to some pseudo code
which traps a concurrency violation (especially WHERE the trapping is
best done, in OnRowUpdated or in the routine that invokes
Adapter.Update); then reads the fresh row from the db and merges the
fresh row with the stale dataset replacing stale values; and then clears
the update error condition so that the dataset is "good to go" after the

I have read lots of general examples but found none where the stale data
is replaced with fresh data.


Cor Ligthert [MVP]


I think that your question is to complex for a complete answer, however two

The use of the acceptchanges triggers us all active in this newsgroup. It is
reseting all the datarows you have done to "no" changes.

Secondly if you are using the rowerrors from the datarow not in combination
with any kind of dataprovider like the inbuild one in the datagrid and
datagridview, than you have to check those in a loop.

I hope it helps something,


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question