Sdílet prostřednictvím


Viewing the Contents of a DataView

A DataView exposes an enumerable collection of DataRowView objects. The DataRowView objects expose values as object arrays that are indexed by either the name or the ordinal reference of the column in the underlying table. You can access the DataRow that is exposed by the DataRowView using the Row property of the DataRowView.

When you view values using a DataRowView, the RowStateFilter property of the DataView determines which row version of the underlying DataRow is exposed. For information about accessing different row versions using a DataRow, see Row States and Row Versions.

The following code example displays all the current and original values in a table.

  Dim catView As DataView = New DataView(catDS.Tables("Categories"))

  Console.WriteLine("Current Values:")

  WriteView(catView)

  Console.WriteLine("Original Values:")

  catView.RowStateFilter = DataViewRowState.ModifiedOriginal

  WriteView(catView)    

Public Shared Sub WriteView(myView As DataView)
  Dim myDRV As DataRowView
  Dim i As Integer

  For Each myDRV In myView
    For i = 0 To myView.Table.Columns.Count - 1
      Console.Write(myDRV(i) & vbTab)
    Next
    Console.WriteLine()
  Next
End Sub
[C#]  DataView catView = new DataView(catDS.Tables["Categories"]);

  Console.WriteLine("Current Values:");

  WriteView(catView);

  Console.WriteLine("Original Values:");

  catView.RowStateFilter = DataViewRowState.ModifiedOriginal;

  WriteView(catView);

public static void WriteView(DataView myView)
{
  foreach (DataRowView myDRV in myView)
  {
    for (int i = 0; i < myView.Table.Columns.Count; i++)
      Console.Write(myDRV[i] + "\t");
    Console.WriteLine();
  }
}

See Also

Viewing Data Using a DataView | DataRowVersion Enumeration | DataViewRowState Enumeration | Creating and Using DataViews | DataView Class | DataRowView Class