c# - AcceptChanges - What's it used for?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Can anybody tell me when you would use DataSet.AcceptChanges. If you use it,
then all the new records are reset to be seen as original records
(unchanged), and hence cannot be updated into the datasource. Therefore I've
been using the update method which does both Accet changes (rebuilds the row
numbers in the data table) & saves to datasource.
I can understand RejectChanges as this would discard new rows before the
update, but why AcceptChanges? When would you use it?

Thanks for any ideas on this
Ant
 
Hi,

Sometimes you could use DataSet as a disconnected source that never works
with the database. Some sort of the local datasource. In this case you could
use AcceptChanges to simulate updated data and continue with the next batch
of the data. I am pretty sure some developers will find some other use of
this functionality
 
Ant,

In addition to Val.

Have a look at this not seldom used code
if (Ds.HasChanges) {da.Update(ds.GetChanges)};
ds.AcceptChanges();

The dataadapter sets all rows that are updated to unchanged (or removes
them), however in this case is the GetChanges a copy of that dataset.
With the ds.AcceptChanges are all rows in the dataset accepted as changed or
removes rows from which is the status deleted.

I hope this gives an idea.

Cor
 
if (Ds.HasChanges) {da.Update(ds.GetChanges)};
ds.AcceptChanges();
As a note, it is often neccesary to call Merge after Update(GetChanges)
so that auto-generated and values changes by other users filled back to
the dataset (if the insert/update/delete command has output params or
return result set).

Thi
 
Truong Hong Thi said:
As a note, it is often neccesary to call Merge after Update(GetChanges)
so that auto-generated and values changes by other users filled back to
the dataset (if the insert/update/delete command has output params or
return result set).

Thi

yepp, just had that case. But I did not want that complicated way of
updating the duplicated rows in GetChanges() and then merge them into the
original dataset again, so i ended up doing something like

dataset.update(dataset.datatable.select(nothing,nothing,DataRowState.Added
Or DataRowState.Modified Or DataRowState.Deleted))

thereby updating the original rows. Does anyone know a good reason for NOT
doing it that way?
 
Back
Top