This documentation is archived and is not being maintained.

DataRow.AcceptChanges Method

Commits all the changes made to this row since the last time AcceptChanges was called.

[Visual Basic]
Public Sub AcceptChanges()
public void AcceptChanges();
public: void AcceptChanges();
public function AcceptChanges();


Exception Type Condition
RowNotInTableException The row does not belong to the table.


When invoking AcceptChanges, the EndEdit method is implicitly called to end any edits. If the RowState of the row was Added or Modified, the tee cref="System.Data.DataRow.RowState"/> becomes Unchanged. If the RowState was Deleted, the row is removed.

See the BeginEdit method for more details.

The DataTable class also has an AcceptChanges method which affects changes made to the entire table.


[Visual Basic, C#, C++] The following example first creates a new DataTable with one column, then creates a single DataRow. As the DataRow is created, added, modified, and deleted, its RowState is printed.

[Visual Basic] 
Private Sub DemonstrateAcceptChanges()
    ' Run a function to create a DataTable with one column.
    Dim myTable As DataTable = MakeTable()
    Dim myRow As DataRow 
    ' Create a new DataRow.
    myRow = myTable.NewRow()
    ' Detached row.
    Console.WriteLine("New Row " & myRow.RowState)
    ' New row.
    Console.WriteLine("AddRow " & myRow.RowState)
    ' Unchanged row.
    Console.WriteLine("AcceptChanges " & myRow.RowState)
    myRow("FirstName") = "Scott"
    ' Modified row.
    Console.WriteLine("Modified " & myRow.RowState)
    ' Deleted row.
    Console.WriteLine("Deleted " & myRow.RowState)
 End Sub
 Private Function MakeTable()As DataTable
    ' Make a simple table with one column.
    Dim dt As DataTable = New DataTable("myTable")
    Dim dcFirstName As DataColumn = New DataColumn("FirstName", Type.GetType("System.String"))
    MakeTable = dt
 End Function

private void DemonstrateAcceptChanges(){
    //Run a function to create a DataTable with one column.
    DataTable myTable = MakeTable();
    DataRow myRow;
    // Create a new DataRow.
    myRow = myTable.NewRow();
    // Detached row.
    Console.WriteLine("New Row " + myRow.RowState);
    // New row.
    Console.WriteLine("AddRow " + myRow.RowState);
    // Unchanged row.
    Console.WriteLine("AcceptChanges " + myRow.RowState);
    myRow["FirstName"] = "Scott";
    // Modified row.
    Console.WriteLine("Modified " + myRow.RowState);
    // Deleted row.
    Console.WriteLine("Deleted " + myRow.RowState);
 private DataTable MakeTable(){
    // Make a simple table with one column.
    DataTable dt = new DataTable("myTable");
    DataColumn dcFirstName = new DataColumn("FirstName", Type.GetType("System.String"));
    return dt;

void DemonstrateAcceptChanges(){
    //Run a function to create a DataTable with one column.
    DataTable* myTable = MakeTable();
    DataRow* myRow;
    // Create a new DataRow.
    myRow = myTable->NewRow();
    // Detached row.
    Console::WriteLine(S"New Row {0}", __box(myRow->RowState));
    // New row.
    Console::WriteLine(S"AddRow {0}", __box(myRow->RowState));
    // Unchanged row.
    Console::WriteLine(S"AcceptChanges {0}", __box(myRow->RowState));
    myRow->Item[S"FirstName"] = S"Scott";
    // Modified row.
    Console::WriteLine(S"Modified {0}", __box(myRow->RowState));
    // Deleted row.
    Console::WriteLine(S"Deleted {0}", __box(myRow->RowState));
 DataTable* MakeTable(){
    // Make a simple table with one column.
    DataTable* dt = new DataTable(S"myTable");
    DataColumn* dcFirstName = new DataColumn(S"FirstName", Type::GetType(S"System.String"));
    return dt;

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

DataRow Class | DataRow Members | System.Data Namespace | AcceptChanges | BeginEdit | CancelEdit | DataViewRowState | DataTable | EndEdit | HasVersion | Item | RowState