Attention: We are retiring the ASP.NET Community Blogs. Learn more >

Calling Merge and AcceptChanges on DataSet

When the Merge or AcceptChanges methods are called on a DataSet, the DataSet notifies all the DataViews bound to it that they must reset the list they are handling and the DataView notifies this to all the bound controls.

For a bound control, a reset must be treated as if the data after the reset is completely different than the data previously presented.

If you are working with a list, a grid for example, you may see the selected row change to another row (the first one in the DataTable) if you call AcceptChanges on DataSet. 

The recommended way to avoid this behavior in bound controls is NOT to use the Merge method of a DataSet and use the ImportRow method of the table and then do the merge in each of the rows that will be merged in order to prevent the Reset.

So instead of calling AcceptChanges in the DataSet, call AcceptChanges only in those DataRows that were updated.

No Comments