Describes the version of data in a DataRow.
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)
Visual Basic (Declaration)
<FlagsAttribute> _
Public Enumeration DataViewRowState
Dim instance As DataViewRowState
[FlagsAttribute]
public enum DataViewRowState
[FlagsAttribute]
public enum class DataViewRowState
public enum DataViewRowState
| Member name | Description |
|---|
.gif) .gif) | None | None. |
.gif) .gif) | Unchanged | An unchanged row. |
.gif) .gif) | Added | A new row. |
.gif) .gif) | Deleted | A deleted row. |
.gif) .gif) | ModifiedCurrent | A current version of original data that has been modified (see ModifiedOriginal). |
.gif) .gif) | ModifiedOriginal | The original version of the data that was modified. (Although the data has since been modified, it is available as ModifiedCurrent). |
.gif) .gif) | OriginalRows | Original rows including unchanged and deleted rows. |
.gif) .gif) | CurrentRows | Current rows including unchanged, new, and modified rows. |
The DataViewRowState values are used either to retrieve a particular version of data from a DataRow, or to determine what versions exist.
Set the RowStateFilter property of the DataView to specify which version or versions of data you want to view.
You can use the Boolean operator Or with the values to get more than one version.
The DataTable uses DataViewRowState in the Select method.
In the following example DataTable is created with a single column. The data is changed, and the RowStateFilter of the DataView is set to display different row sets, depending on the DataViewRowState.
Private Sub DemonstrateRowState()
Dim i As Integer
' Create a DataTable with one column.
Dim dataTable As New DataTable("dataTable")
Dim dataColumn As New DataColumn("dataColumn")
dataTable.Columns.Add(dataColumn)
' Add ten rows.
Dim dataRow As DataRow
For i = 0 To 9
dataRow = dataTable.NewRow()
dataRow("dataColumn") = "item " + i.ToString()
dataTable.Rows.Add(dataRow)
Next i
dataTable.AcceptChanges()
' Create a DataView with the table.
Dim dataView As New DataView(dataTable)
' Change one row's value:
dataTable.Rows(1)("dataColumn") = "Hello"
' Add one row:
dataRow = dataTable.NewRow()
dataRow("dataColumn") = "World"
dataTable.Rows.Add(dataRow)
' Set the RowStateFilter to display only Added and modified rows.
dataView.RowStateFilter = _
DataViewRowState.Added Or DataViewRowState.ModifiedCurrent
' Print those rows. Output = "Hello" "World";
PrintView(dataView, "ModifiedCurrent and Added")
' Set filter to display on originals of modified rows.
dataView.RowStateFilter = DataViewRowState.ModifiedOriginal
PrintView(dataView, "ModifiedOriginal")
' Delete three rows.
dataTable.Rows(1).Delete()
dataTable.Rows(2).Delete()
dataTable.Rows(3).Delete()
' Set the RowStateFilter to display only Added and modified rows.
dataView.RowStateFilter = DataViewRowState.Deleted
PrintView(dataView, "Deleted")
'Set filter to display only current.
dataView.RowStateFilter = DataViewRowState.CurrentRows
PrintView(dataView, "Current")
' Set filter to display only unchanged rows.
dataView.RowStateFilter = DataViewRowState.Unchanged
PrintView(dataView, "Unchanged")
' Set filter to display only original rows.
dataView.RowStateFilter = DataViewRowState.OriginalRows
PrintView(dataView, "OriginalRows")
End Sub
Private Sub PrintView(ByVal dataView As DataView, ByVal label As String)
Console.WriteLine(ControlChars.Cr + label)
Dim i As Integer
For i = 0 To dataView.Count - 1
Console.WriteLine(dataView(i)("dataColumn"))
Next i
End Sub
static private void DemonstrateRowState()
{
// Create a DataTable with one column.
DataTable dataTable = new DataTable("dataTable");
DataColumn dataColumn = new DataColumn("dataColumn");
dataTable.Columns.Add(dataColumn);
// Add ten rows.
DataRow dataRow;
for (int i = 0; i < 10; i++)
{
dataRow = dataTable.NewRow();
dataRow["dataColumn"] = "item " + i;
dataTable.Rows.Add(dataRow);
}
dataTable.AcceptChanges();
// Create a DataView with the table.
DataView dataView = new DataView(dataTable);
// Change one row's value:
dataTable.Rows[1]["dataColumn"] = "Hello";
// Add one row:
dataRow = dataTable.NewRow();
dataRow["dataColumn"] = "World";
dataTable.Rows.Add(dataRow);
// Set the RowStateFilter to display only added and modified rows.
dataView.RowStateFilter = DataViewRowState.Added
| DataViewRowState.ModifiedCurrent;
// Print those rows. Output = "Hello" "World";
PrintView(dataView, "ModifiedCurrent and Added");
// Set filter to display on originals of modified rows.
dataView.RowStateFilter = DataViewRowState.ModifiedOriginal;
PrintView(dataView, "ModifiedOriginal");
// Delete three rows.
dataTable.Rows[1].Delete();
dataTable.Rows[2].Delete();
dataTable.Rows[3].Delete();
// Set the RowStateFilter to display only Added and modified rows.
dataView.RowStateFilter = DataViewRowState.Deleted;
PrintView(dataView, "Deleted");
//Set filter to display only current.
dataView.RowStateFilter = DataViewRowState.CurrentRows;
PrintView(dataView, "Current");
// Set filter to display only unchanged rows.
dataView.RowStateFilter = DataViewRowState.Unchanged;
PrintView(dataView, "Unchanged");
// Set filter to display only original rows.
dataView.RowStateFilter = DataViewRowState.OriginalRows;
PrintView(dataView, "OriginalRows");
}
static private void PrintView(DataView dataView, string label)
{
Console.WriteLine("\n" + label);
for (int i = 0; i < dataView.Count; i++)
{
Console.WriteLine(dataView[i]["dataColumn"]);
}
}
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
.NET Compact Framework
Supported in: 3.5, 2.0, 1.0
XNA Framework
Supported in: 3.0, 2.0, 1.0
Reference