.NET Framework Class Library  

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#] 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++, JScript] No example is available for C++ or JScript. To view a Visual Basic 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 - Windows CE .NET

See Also

DataRow Class | DataRow Members | System.Data Namespace | AcceptChanges | BeginEdit | Add | CancelEdit | DataTable | DataRowView | Delete | EndEdit | NewRow