Order of using AcceptChanges and TableAdapter.Update

Do you need to use AcceptChanges after a TableAdapter.Update I know it's an option for DataAdapters, but I'm guessing it's automatically called during a TableAdapter.Update. Is that true

Also, I believe that calling AcceptChanges before a TableAdapter.Update will lose you your ability to apply the changes to the underlying data source, right

If both these assumptions are correct (don't call AcceptChanges before Update and that update calls AcceptChanges on its own), then an application managing its data resources via TableAdapters and BindingSources should never have an occasion to call AcceptChanges, no



Answer this question

Order of using AcceptChanges and TableAdapter.Update

  • Mario Esposito

    Thanks. That's terrific! So I was mostly right, except that I have to use AcceptChanges after GetChanges.

    The only remaining question is that the documentation mentions that when using a DataAdapter, the call to AcceptChanges is a user option. Is that correct


  • Timski72

    Let me explain exactly what AcceptChanges does in relatively simplistic terms. Every DataRow has two sets of data: original and current. It also has a RowState property that pretty much describes the relationship between those two sets of data. Unchanged means that both sets of data are the same. Added means that the original data is empty and the current data represents a new record that will be inserted. Modified means that the cuurent data is not the same as the original data, but both exist. Deleted means that the current data is empty and the original data represents a record that will be deleted. When you call AcceptChanges, the original data is overwritten with the current data and all RowState properties are set to Unchanged. Calling Update on a DataAdapter or TableAdapter looks for DataRows with RowStates of Deleted, Added and Modified and synchronises the database with the current data in each row. If you've already called AcceptChanges then there are no rows with those RowStates so nothing happens. The other thing is that Update implicitly calls AcceptChanges after a successful call. Generally speaking, the only time you should need to call AccpetChanges is if you're using GetChanges, e.g. you call GetChanges and pass the result to a call to Update, then you need to call AcceptChanges on the original data so it is in sync with the now updated database.

  • Order of using AcceptChanges and TableAdapter.Update