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
The DataRowState enumeration is returned by the RowState property of the DataRow class.
| 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 |
[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.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++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button
in the upper-left corner of the page.
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 - Windows CE .NET
Assembly: System.Data (in System.Data.dll)
System.Data Namespace | DataRow | Delete | NewRow | DataRowCollection