Export (0) Print
Expand All

DataRow.RowState Property

Gets the current state of the row in regard to its relationship to the DataRowCollection.

[Visual Basic]
Public ReadOnly Property RowState As DataRowState
[C#]
public DataRowState RowState {get;}
[C++]
public: __property DataRowState get_RowState();
[JScript]
public function get RowState() : DataRowState;

Property Value

One of the DataRowState values.

Remarks

The value of the RowState depends on two factors: (1) the kind of operation has been performed on the row, and (2) whether or not AcceptChanges has been called on the DataRow.

Example

[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 DemonstrateRowState()
    ' 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)
 
    myTable.Rows.Add(myRow)
    ' New row.
    Console.WriteLine("AddRow " & myRow.RowState)
 
    myTable.AcceptChanges()
    ' Unchanged row.
    Console.WriteLine("AcceptChanges " & myRow.RowState)
 
    myRow("FirstName") = "Scott"
    ' Modified row.
    Console.WriteLine("Modified " & myRow.RowState)
 
    myRow.Delete()
    ' Deleted row.
    Console.WriteLine("Deleted " & myRow.RowState)
 End Sub
 
 Private Function MakeTable() As DataTable
    ' Make a simple table with one column.
    Dim myTable As DataTable = New DataTable("myTable")
    Dim dcFirstName As DataColumn = New DataColumn("FirstName", Type.GetType("System.String"))
    myTable.Columns.Add(dcFirstName)
    MakeTable = myTable
 End Function

[C#] 
private void DemonstrateRowState(){
    // 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);
 
    myTable.Rows.Add(myRow);
    // New row.
    Console.WriteLine("AddRow " + myRow.RowState);
 
    myTable.AcceptChanges();
    // Unchanged row.
    Console.WriteLine("AcceptChanges " + myRow.RowState);
 
    myRow["FirstName"] = "Scott";
    // Modified row.
    Console.WriteLine("Modified " + myRow.RowState);
 
    myRow.Delete();
    // Deleted row.
    Console.WriteLine("Deleted " + myRow.RowState);
 }
 
 private DataTable MakeTable(){
    // Make a simple table with one column.
    DataTable myTable = new DataTable("myTable");
    DataColumn dcFirstName = new DataColumn("FirstName", Type.GetType("System.String"));
    myTable.Columns.Add(dcFirstName);
    return myTable;
 }

[C++] 
private:
void DemonstrateRowState(){
    // 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));
 
    myTable->Rows->Add(myRow);
    // New row.
    Console::WriteLine(S"AddRow {0}", __box(myRow->RowState));
 
    myTable->AcceptChanges();
    // 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));
 
    myRow->Delete();
    // Deleted row.
    Console::WriteLine(S"Deleted {0}", __box(myRow->RowState));
 }
 
 DataTable* MakeTable(){
    // Make a simple table with one column.
    DataTable* myTable = new DataTable(S"myTable");
    DataColumn* dcFirstName = new DataColumn(S"FirstName", Type::GetType(S"System.String"));
    myTable->Columns->Add(dcFirstName);
    return myTable;
 }

[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.

Requirements

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 | Add | CancelEdit | DataTable | DataRowView | Delete | EndEdit | NewRow

Show:
© 2015 Microsoft