Paul Michaels
Paul Michaels

Reputation: 16685

Use of AcceptChanges with SQL Server

I'm confused as to the effect of using AcceptChanges within a dataset. It appears from my tests that this forces the database changes to be comitted, disregarding any constraints on the database.

Can anyone confirm if this is the case, or if not, how this differs from using the Update function on the dataset?

Upvotes: 4

Views: 1162

Answers (1)

Rune Grimstad
Rune Grimstad

Reputation: 36300

AcceptChanges doesn't affect your database, it only affects the DataSet (your in-memory copy of the data).

Using AcceptChanges will cause all Datarows of all tables in the data set to have its Rowstate reset to RowState.Unchanged.

You would normally use AcceptChanges together with the DataTable.GetChanges method. Or with the DbDataAdapter.Update method. You would use either of them to get the changes or to persist the changes to the database, and you would then use AcceptChanges to tell the DataSet that the changes have been stored.

Upvotes: 9

Related Questions