AcceptChanges Method
This documentation is archived and is not being maintained.

DataSet.AcceptChanges Method

Commits all the changes made to this DataSet since it was loaded or since the last time AcceptChanges was called.

[Visual Basic]
Public Sub AcceptChanges()
[C#]
public void AcceptChanges();
[C++]
public: void AcceptChanges();
[JScript]
public function AcceptChanges();

Remarks

Both the DataRow and DataTable classes also have AcceptChanges methods. Calling AcceptChanges at the DataTable level causes the AcceptChanges method for each DataRow to be called. Similarly, invoking AcceptChanges on the DataSet causes AcceptChanges to be called on each table within the DataSet. In this manner, you have multiple levels at which the method can be invoked. Calling the AcceptChanges of the DataSet enables you to invoke the method on all subordinate objects (for example, tables and rows) with one call.

When you call AcceptChanges on the DataSet, any DataRow objects still in edit-mode successfully end their edits. The RowState property of each DataRow also changes; Added and Modified rows become Unchanged, and Deleted rows are removed.

If the DataSet contains ForeignKeyConstraint objects, invoking the AcceptChanges method also causes the AcceptRejectRule to be enforced.

Example

[Visual Basic, C#, C++] The following example adds a DataRow to a DataTable in a DataSet. The AcceptChanges method is then called on the DataSet, which cascades to all DataTable objects it contains.

[Visual Basic] 
Private Sub AcceptChanges()
   Dim myDataSet As DataSet
   myDataSet = new DataSet()

   ' Not shown: methods to fill the DataSet with data.
   Dim t As DataTable

   t = myDataSet.Tables("Suppliers")

   ' Add a DataRow to a table.
   Dim myRow As DataRow
   myRow = t.NewRow()
   myRow("CompanyID") = "NWTRADECO"
   myRow("CompanyName") = "NortWest Trade Company"

   ' Add the row.
   t.Rows.Add( myRow )

   ' Calling AcceptChanges on the DataSet causes AcceptChanges to be
   ' called on all subordinate objects.
   myDataSet.AcceptChanges()
End Sub

[C#] 
private void AcceptChanges()
{
   DataSet myDataSet;
   myDataSet = new DataSet();

   // Not shown: methods to fill the DataSet with data.
   DataTable t;
   t = myDataSet.Tables["Suppliers"];

   // Add a DataRow to a table.
   DataRow myRow;
   myRow = t.NewRow();
   myRow["CompanyID"] = "NWTRADECO";
   myRow["CompanyName"] = "NortWest Trade Company";

   // Add the row.
   t.Rows.Add( myRow );

   // Calling AcceptChanges on the DataSet causes AcceptChanges to be
   // called on all subordinate objects.
   myDataSet.AcceptChanges();
}

[C++] 
private:
void AcceptChanges()
{
   DataSet* myDataSet;
   myDataSet = new DataSet();

   // Not shown: methods to fill the DataSet with data.
   DataTable* t;
   t = myDataSet->Tables->Item[S"Suppliers"];

   // Add a DataRow to a table.
   DataRow* myRow;
   myRow = t->NewRow();
   myRow->Item[S"CompanyID"] = S"NWTRADECO";
   myRow->Item[S"CompanyName"] = S"NortWest Trade Company";

   // Add the row.
   t->Rows->Add( myRow );

   // Calling AcceptChanges on the DataSet causes AcceptChanges to be
   // called on all subordinate objects.
   myDataSet->AcceptChanges();
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

DataSet Class | DataSet Members | System.Data Namespace | AcceptChanges | AcceptRejectRule | BeginEdit | DataRow | ForeignKeyConstraint

Show:
© 2016 Microsoft