DataTable.AcceptChanges 메서드

정의

마지막으로 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 또한 모든 행과 Modified 행이 Unchanged변경 Added 되고 Deleted 행이 제거됩니다.

AcceptChanges 메서드는 일반적으로 메서드를 DataTable 사용하여 업데이트 DataSet 하려고 시도한 후에 호출됩니다DbDataAdapter.Update.

적용 대상

추가 정보