DataSet.AcceptChanges DataSet.AcceptChanges DataSet.AcceptChanges DataSet.AcceptChanges Method

定义

提交自加载此 DataSet 或上次调用 AcceptChanges() 以来对其进行的所有更改。Commits all the changes made to this DataSet since it was loaded or since the last time AcceptChanges() was called.

public:
 void AcceptChanges();
public void AcceptChanges ();
member this.AcceptChanges : unit -> unit
Public Sub AcceptChanges ()

示例

下面的示例将添加DataRow到中DataTable DataSet的。The following example adds a DataRow to a DataTable in a DataSet. 然后在DataTable上调用AcceptChanges方法,该方法可与它包含的所有对象DataSet进行级联。The AcceptChanges method is then called on the DataSet, which cascades to all DataTable objects that it contains.

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();
}
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

注解

和类都包含AcceptChanges方法。 DataRow DataTableBoth the DataRow and DataTable classes have AcceptChanges methods. 在级别调用AcceptChanges将导致AcceptChanges调用每个DataRow的方法。 DataTableCalling AcceptChanges at the DataTable level causes the AcceptChanges method for each DataRow to be called. 同样, AcceptChanges AcceptChanges对中的DataSet每个表调用DataSet会导致的。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. AcceptChanges 通过调用的,你可以通过一个调用对所有从属对象(例如,表和DataSet行)调用方法。Calling the AcceptChanges of the DataSet enables you to invoke the method on all subordinate objects (for example, tables and rows) with one call.

当在AcceptChanges DataRow上调用时,仍处于编辑模式的任何对象都将成功完成其编辑。 DataSetWhen you call AcceptChanges on the DataSet, any DataRow objects still in edit-mode end their edits successfully. 每个DataRow的属性也会更改; RowStateAdded和行将Modified 变为Unchanged,并Deleted删除行。The RowState property of each DataRow also changes; Added and Modified rows become Unchanged, and Deleted rows are removed.

AcceptChanges AcceptRejectRule如果包含对象ForeignKeyConstraint ,则调用方法还会导致强制执行。 DataSetIf the DataSet contains ForeignKeyConstraint objects, invoking the AcceptChanges method also causes the AcceptRejectRule to be enforced.

备注

AcceptChanges``RejectChanges仅适用于相关更改(即,添加、删除、DataRow删除和修改)。AcceptChanges and RejectChanges only apply to DataRow related changes (that is, Add, Remove, Delete, and Modify). 它们不适用于架构或结构更改。They are not applicable to schema or structural changes.

如果已使用 DataAdapter 填充 DataSet,则调用 AcceptChange 不会将这些更改复制回数据源中。Calling AcceptChanges will not replicate these changes back to the data source if the DataSet was filled using a DataAdapter. 在此情况下,请改为调用 UpdateIn that situation, call Update instead. 有关详细信息,请参阅通过 Dataadapter 更新数据源See Updating Data Sources with DataAdapters for more information.

适用于

另请参阅