DataTable.AcceptChanges メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
前回 AcceptChanges() を呼び出した以降にこのテーブルに対して行われたすべての変更をコミットします。
public:
void AcceptChanges();
public void AcceptChanges ();
member this.AcceptChanges : unit -> unit
Public Sub AcceptChanges ()
例
次の例では、各テーブルでエラーをテストします。 テーブルのエラーを (未定義の関数に渡すことによって) AcceptChanges 調整できる場合は呼び出されます。それ以外の場合は呼 RejectChanges び出されます。
private void AcceptOrReject(DataTable table)
{
// If there are errors, try to reconcile.
if(table.HasErrors)
{
if(Reconcile(table))
{
// Fixed all errors.
table.AcceptChanges();
}
else
{
// Couldn'table fix all errors.
table.RejectChanges();
}
}
else
{
// If no errors, AcceptChanges.
table.AcceptChanges();
}
}
private bool Reconcile(DataTable thisTable)
{
foreach(DataRow row in thisTable.Rows)
{
//Insert code to try to reconcile error.
// If there are still errors return immediately
// since the caller rejects all changes upon error.
if(row.HasErrors)
return false;
}
return true;
}
Private Sub AcceptOrReject(table As DataTable)
' If there are errors, try to reconcile.
If (table.HasErrors) Then
If (Reconcile(table)) Then
' Fixed all errors.
table.AcceptChanges()
Else
' Couldn'table fix all errors.
table.RejectChanges()
End If
Else
' If no errors, AcceptChanges.
table.AcceptChanges()
End If
End Sub
Private Function Reconcile(thisTable As DataTable) As Boolean
Dim row As DataRow
For Each row in thisTable.Rows
'Insert code to try to reconcile error.
' If there are still errors return immediately
' since the caller rejects all changes upon error.
If row.HasErrors Then
Reconcile = False
Exit Function
End If
Next row
Reconcile = True
End Function
注釈
呼び出されると AcceptChanges 、 DataRow 編集モードのオブジェクトは正常に編集を終了します。 また、DataRowStateすべてのAdded
行がModified
変更されDeleted
、行Unchanged
が削除されます。
メソッドはAcceptChanges、通常、メソッドをDataTable使用してDbDataAdapter.Update更新を試みた後にDataSet呼び出されます。