DataRowState Enumeration
Gets the state of a DataRow object.
This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.
Assembly: System.Data (in System.Data.dll)
| Member name | Description | |
|---|---|---|
| Added | The row has been added to a DataRowCollection, and AcceptChanges has not been called. | |
| Deleted | ||
| Detached | 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. | |
| Modified | The row has been modified and AcceptChanges has not been called. | |
| Unchanged | The row has not changed since AcceptChanges was last called. |
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.
Private Sub DemonstrateRowState() 'Run a function to create a DataTable with one column. Dim dataTable As DataTable = MakeTable() Dim dataRow As DataRow ' Create a new DataRow. dataRow = dataTable.NewRow() ' Detached row. Console.WriteLine(String.Format("New Row {0}", dataRow.RowState)) dataTable.Rows.Add(dataRow) ' New row. Console.WriteLine(String.Format("AddRow {0}", dataRow.RowState)) dataTable.AcceptChanges() ' Unchanged row. Console.WriteLine(String.Format("AcceptChanges {0}", dataRow.RowState)) dataRow("FirstName") = "Scott" ' Modified row. Console.WriteLine(String.Format("Modified {0}", dataRow.RowState)) dataRow.Delete() ' Deleted row. Console.WriteLine(String.Format("Deleted {0}", dataRow.RowState)) End Sub Private Function MakeTable() As DataTable ' Make a simple table with one column. Dim dt As New DataTable("dataTable") Dim firstName As New DataColumn("FirstName", _ Type.GetType("System.String")) dt.Columns.Add(firstName) Return dt End Function
Available since 1.1