DataRow.AcceptChanges DataRow.AcceptChanges DataRow.AcceptChanges DataRow.AcceptChanges Method

정의

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

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

예외

행이 테이블에 속하지 않는 경우The row does not belong to the table.

예제

다음 예제에서는 먼저 새로 만듭니다 DataTable 하나의 열이 있는 단일 다음 만들고 DataRow합니다.The following example first creates a new DataTable with one column, and then creates a single DataRow. DataRow 는 생성, 추가, 수정 및 삭제, 해당 RowState 출력 됩니다.As the DataRow is created, added, modified, and deleted, its RowState is printed.

   private void DemonstrateAcceptChanges()
   {
       //Run a function to create a DataTable with one column.
       DataTable table = MakeTable();
       DataRow row;

       // Create a new DataRow.
       row = table.NewRow();
       // Detached row.
       Console.WriteLine("New Row " + row.RowState);

       table.Rows.Add(row);
       // New row.
       Console.WriteLine("AddRow " + row.RowState);

       table.AcceptChanges();
       // Unchanged row.
       Console.WriteLine("AcceptChanges " + row.RowState);

       row["FirstName"] = "Scott";
       // Modified row.
       Console.WriteLine("Modified " + row.RowState);

       row.Delete();
       // Deleted row.
       Console.WriteLine("Deleted " + row.RowState);
   }

   private DataTable MakeTable()
   {
       // Make a simple table with one column.
       DataTable table = new DataTable("table");
       DataColumn fnameColumn = new DataColumn(
           "FirstName", Type.GetType("System.String"));
       table.Columns.Add(fnameColumn);
       return table;
   }
Private Sub DemonstrateAcceptChanges()
    ' Run a function to create a DataTable with one column.
    Dim table As DataTable = MakeTable()
    Dim row As DataRow 
 
    ' Create a new DataRow.
    row = table.NewRow()
    ' Detached row.
    Console.WriteLine("New Row " & row.RowState)
 
    table.Rows.Add(row)
    ' New row.
    Console.WriteLine("AddRow " & row.RowState)
 
    table.AcceptChanges()
    ' Unchanged row.
    Console.WriteLine("AcceptChanges " & row.RowState)
 
    row("FirstName") = "Scott"
    ' Modified row.
    Console.WriteLine("Modified " & row.RowState)
 
    row.Delete()
    ' Deleted row.
    Console.WriteLine("Deleted " & row.RowState)
 End Sub
 
 Private Function MakeTable()As DataTable
    ' Make a simple table with one column.
    Dim table As New DataTable("table")
    Dim fnameColumn As New DataColumn( _
        "FirstName", Type.GetType("System.String"))
    table.Columns.Add(fnameColumn)
    MakeTable = table
 End Function

설명

호출할 때 AcceptChanges, EndEdit 암시적으로 메서드는 편집을 끝냅니다.When invoking AcceptChanges, the EndEdit method is implicitly called to end any edits. 경우는 RowState 행의 추가 또는 수정 된는 RowState 됩니다 Unchanged 합니다.If the RowState of the row was Added or Modified, the RowState becomes Unchanged. 경우는 RowState 된 삭제 된 행이 제거 됩니다.If the RowState was Deleted, the row is removed.

자세한 내용은 BeginEdit 메서드를 참조하세요.See the BeginEdit method for more information.

합니다 DataTable 클래스에는 AcceptChanges 메서드는 전체 테이블 변경에 영향을 줍니다.The DataTable class also has an AcceptChanges method which affects changes made to the whole table. 자세한 내용 및 적용 하 고 개별 데이터 행에 대 한 변경을 거부 하는 방법을 보여 주는 코드 예제를 참조 하세요 AcceptChanges 및 RejectChanges합니다.For more information and a code example that demonstrates how to accept and reject changes to individual data rows, see AcceptChanges and RejectChanges.

적용 대상

추가 정보