Home All Groups Group Topic Archive Search About

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

Author
7 Mar 2006 1:42 AM
Ant
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

Author
7 Mar 2006 2:59 AM
Val Mazur (MVP)
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

--
Val Mazur
Microsoft MVP
http://xport.mvps.org


Show quote
"Ant" <A**@discussions.microsoft.com> wrote in message
news:0F373379-602E-491B-B553-69247D0B8BD8@microsoft.com...
> 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
Author
7 Mar 2006 6:46 AM
Cor Ligthert [MVP]
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


Show quote
"Ant" <A**@discussions.microsoft.com> schreef in bericht
news:0F373379-602E-491B-B553-69247D0B8BD8@microsoft.com...
> 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
Author
7 Mar 2006 8:51 AM
Truong Hong Thi
> 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
Author
7 Mar 2006 5:58 PM
Christian Dams
"Truong Hong Thi" <thi1***@gmail.com> schrieb im Newsbeitrag
news:1141721502.357158.52000@z34g2000cwc.googlegroups.com...
>> 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
>

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?

AddThis Social Bookmark Button