DataTable.AcceptChanges DataTable.AcceptChanges DataTable.AcceptChanges DataTable.AcceptChanges Method

정의

AcceptChanges()가 마지막으로 호출된 이후 이 테이블에서 변경된 내용을 모두 커밋합니다.Commits all the changes made to this table since the last time AcceptChanges() was called.

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

예제

다음 예제에서는 각 테이블의 오류를 테스트합니다.The following example tests each table for errors. (전달 하 여 정의 되지 않은 함수), 테이블의 오류를 해결할 수 있으면 AcceptChanges 이 고, 그렇지 않으면 호출 RejectChanges 라고 합니다.If the table's errors can be reconciled (by passing it to an undefined function), AcceptChanges is called; otherwise, RejectChanges is called.

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 아직 편집 모드에에서는 개체의 편집을 성공적으로 종료 합니다.When AcceptChanges is called, any DataRow object still in edit mode successfully ends its edits. 합니다 DataRowState 도 변경: 모든 Added 하 고 Modified 될 행 Unchanged, 및 Deleted 행이 제거 됩니다.The DataRowState also changes: all Added and Modified rows become Unchanged, and Deleted rows are removed.

AcceptChanges 메서드를 일반적으로 호출을 DataTable 업데이트 하려고 하면 후 합니다 DataSet 를 사용 하 여를 DbDataAdapter.Update 메서드.The AcceptChanges method is generally called on a DataTable after you attempt to update the DataSet using the DbDataAdapter.Update method.

적용 대상

추가 정보