DataRowState Enumeration
Gets the state of a DataRow object.
This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.
[Visual Basic] <Flags> <Serializable> Public Enum DataRowState [C#] [Flags] [Serializable] public enum DataRowState [C++] [Flags] [Serializable] __value public enum DataRowState [JScript] public Flags Serializable enum DataRowState
Remarks
The DataRowState enumeration is returned by the RowState property of the DataRow class.
Members
| Member name | Description | Value |
|---|---|---|
| Added Supported by the .NET Compact Framework. | The row has been added to a DataRowCollection, and AcceptChanges has not been called. | 4 |
| Deleted Supported by the .NET Compact Framework. | The row was deleted using the Delete method of the DataRow. | 8 |
| Detached Supported by the .NET Compact Framework. | The row has been created but is not part of any DataRowCollection. A DataRow is in this state immediately after it has been created and before it is added to a collection, or if it has been removed from a collection. | 1 |
| Modified Supported by the .NET Compact Framework. | The row has been modified and AcceptChanges has not been called. | 16 |
| Unchanged Supported by the .NET Compact Framework. | The row has not changed since AcceptChanges was last called. | 2 |
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.ToString()) myTable.Rows.Add(myRow) ' New row. Console.WriteLine("AddRow " + myRow.RowState.ToString()) myTable.AcceptChanges() ' Unchanged row. Console.WriteLine("AcceptChanges " + myRow.RowState.ToString()) myRow("FirstName") = "Scott" ' Modified row. Console.WriteLine("Modified " + myRow.RowState.ToString()) myRow.Delete() ' Deleted row. Console.WriteLine("Deleted " + myRow.RowState.ToString()) End Sub Private Function MakeTable() As DataTable ' Make a simple table with one column. Dim dt As New DataTable("myTable") Dim dcFirstName As New DataColumn("FirstName", _ Type.GetType("System.String")) dt.Columns.Add(dcFirstName) Return dt 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 dt = new DataTable("myTable"); DataColumn dcFirstName = new DataColumn("FirstName", Type.GetType("System.String")); dt.Columns.Add(dcFirstName); return dt; } [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* dt = new DataTable(S"myTable"); DataColumn* dcFirstName = new DataColumn(S"FirstName", Type::GetType(S"System.String")); dt->Columns->Add(dcFirstName); return dt; }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.Data
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
Assembly: System.Data (in System.Data.dll)
See Also
System.Data Namespace | DataRow | Delete | NewRow | DataRowCollection