Reputation: 8899
Datatable.acceptchanges commits data to the table...means
will it insert data to the table ..or datatable?
Upvotes: 17
Views: 38780
Reputation: 1171
Okay - If I have this right, explicitly calling a DT.CommitChanges() will set all rows to UNCHANGED. And if that is true, when calling DA.UPDATE(DT), any changes you made to the datatable will be ignored.
So it seems, you should only call DT.CommitChanges() for those changes that you DO NOT want to reach the database.
Therefore, changes DO make it to the .NET datatable, regardless of the CommitChanges call, but to get changes to the database table, don't call a CommitChanges prior to performing the DA.Update. And of course implying that DA.Update must be called to actually pushed the changes to the database...
Upvotes: 0
Reputation: 993
Some people choose to manipulate the data in a datatable, examples are deleting certain rows or hanging all names to uppercase. removing NULL
's and so on.
AcceptChanges
just saves these changes to the datatable.
If you want to commit the changes you need to use a dataadaptor or use another method to get the data from the datarows in the datatable and commit the changes.
Upvotes: 3
Reputation: 1
In my case it was caused by auto-number field in database, I suggest below call update methof of data adapter call update /// for auto number column call acceptchanges of datatable
Then re-fill table through oledbadapter. If u do not need to autonumber field, do not add that as a parameter in deletecommand of oledbadapter
Upvotes: 0
Reputation: 6983
The purpose of AcceptChanges() is to let the DataTable know that its data has been saved to the database. All DataRows in the DataTable have their row.RowState set to DataRowState.Unchanged.
It does not save the data to the database. That is done separately.
Upvotes: 14
Reputation: 83366
Here's the documentation:
When AcceptChanges is called, any DataRow object still in edit mode successfully ends its edits. The DataRowState also changes: all Added and Modified rows become Unchanged, and Deleted rows are removed.
The AcceptChanges method is generally called on a DataTable after you attempt to update the DataSet using the DbDataAdapter.Update method.
So your actual database is unaffected.
Upvotes: 7