The AcceptChanges method of DataView should only be used when you "accept the
changes" and you don't wanna update the database or in other word, only
update the presentation layer. (which means AcceptChanges method is a very
easy way to set the RowState of each DataRow object to unchange, so you don't
have to set the RowState in each DataRow object)
when the update method of the DataAdapter is called, it will called the
AcceptChanges method after it update the database.
"Johann Blake" wrote:
> I'm not sure that I entirely understand the purpose of the
> AcceptChanges methon in a DataView. I added a new record to a DataView
> and noticed that its RowState indicated it as being "Added". If I
> execute the Update method on an adapter for the table that the DataView
> is based on, the new record will indeed be written to the database. But
> if I call AcceptChanges prior to executing the Update method, the
> RowState for the new record is changed to "Unchanged" and the new
> record is not stored in the database when the Update method is
> executed.
>
> I don't get it. The .NET documentation clearly states the following:
>
> "Calling AcceptChanges on the DataSet, DataTable, or DataRow will cause
> all Original values for a DataRow to be overwritten with the Current
> values for the DataRow"
>
> and...
>
> "After verifying the accuracy of changes made to data in a DataTable,
> you can accept the changes using the AcceptChanges method of the
> DataRow, DataTable, or DataSet, which will set the Current row values
> to be the Original values and will set the RowState property to
> Unchanged"
The documentation clearly states that after AcceptChanges method is called
it will ONLY change the RowState to "Unchanged" WITHOUT update the database.
>
> This is exactly what it is doing but what's the logic for not allowing
> this newly added record to be stored in the database. Just because the
> RowState now indicates "Unchanged", this should mean that the new
> record should not be stored?? What then is the point of AcceptChanges
> if you can't store the changes you've accepted?
>
> Thanks for your response.
> Johann Blake
>
>
Hope it helps
Ivan Wong
|