Export (0) Print
Expand All
Expand Minimize
4 out of 4 rated this helpful - Rate this topic

DataRowState Enumeration

Gets the state of a DataRow object.

This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.

Namespace: System.Data
Assembly: System.Data (in system.data.dll)

'Declaration
<FlagsAttribute> _
Public Enumeration DataRowState
'Usage
Dim instance As DataRowState

/** @attribute FlagsAttribute() */ 
public enum DataRowState
FlagsAttribute 
public enum DataRowState
 Member nameDescription
Supported by the .NET Compact FrameworkAddedThe row has been added to a DataRowCollection, and AcceptChanges has not been called. 
Supported by the .NET Compact FrameworkDeletedThe row was deleted using the Delete method of the DataRow
Supported by the .NET Compact FrameworkDetachedThe 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. 
Supported by the .NET Compact FrameworkModifiedThe row has been modified and AcceptChanges has not been called. 
Supported by the .NET Compact FrameworkUnchangedThe row has not changed since AcceptChanges was last called. 

The DataRowState enumeration is returned by the RowState property of the DataRow class.

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

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.