DataSet.AcceptChanges 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
會提交自載入或上次AcceptChanges()呼叫以來所有變更DataSet。
public:
void AcceptChanges();
public void AcceptChanges();
member this.AcceptChanges : unit -> unit
Public Sub AcceptChanges ()
範例
以下範例將 a DataRow 加到 a DataTable 中。DataSet AcceptChanges接著,該方法在 上DataSet被呼叫,並級聯到其所包含的所有DataTable物件。
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
備註
和 類別都有 DataRowDataTableAcceptChanges 方法。 在 該DataTable層級呼叫AcceptChanges會觸發AcceptChanges每個 DataRow Call 的方法。 同樣地,在 AcceptChangesDataSetAcceptChanges 每個表 DataSet中要呼叫的原因。 如此一來,方法可被調用的層次多重。 呼叫 AcceptChanges 的 DataSet 可以讓你一次呼叫,對所有從屬物件(例如資料表和列)呼叫該方法。
當你呼叫 AcceptChangesDataSet時,任何 DataRow 仍在編輯模式的物件都能成功結束他們的編輯。
RowState每個DataRow的性質也會改變;Added行Modified變成 ,行Deleted被Unchanged移除。
若 contains DataSetForeignKeyConstraint 物件,呼叫該 AcceptChanges 方法也會強制 AcceptRejectRule 執行。
備註
AcceptChanges 且 RejectChanges 僅適用於 DataRow 相關變更(即新增、移除、刪除與修改)。 它們不適用於結構或結構變更。
若資料集是使用 DataAdapter 填充,呼叫 AcceptChanges 將無法將這些變更複製回資料來源。 在這種情況下,請直接打電話 Update 。 更多資訊請參閱「 使用資料適配器更新 資料來源」。