OHM,
Don't confuse selecting the row with selecting the values of the row.
Remember that each ROW has multiple values associated with it. So the Select
statement is returning all the rows that are "Original Rows", your for each
then is selecting the Current Values of those rows, as the default for
DataRow.Item is current value!
Also remember that the DataView returns DataRowView objects, that the
default for the DataRowView.Item property is the row state for the view.
Try the following code:
Dim view As New DataView(MyTable, Nothing, Nothing,
DataViewRowState.OriginalRows)
For Each row As DataRowView In view
Debug.WriteLine(row("Data"), "DataRowView")
Debug.WriteLine(row.Row("Data"), "DataRow")
Next
added to your code posted earlier (later?):
'create a new table
Dim MyTable As New DataTable
'create a column
MyTable.Columns.Add(New DataColumn("Data"))
'Create Rows
Dim r As DataRow
Dim i As Integer
For i = 0 To 5
r = MyTable.NewRow()
r("Data") = "Item" & i.ToString()
MyTable.Rows.Add(r)
Next
MyTable.AcceptChanges()
'Ok Lets Print out the rows unmodified
Debug.WriteLine("------- Unmodified ---------")
For Each r In MyTable.Rows
Debug.WriteLine(r("Data"))
Next
'Now lets Modify one element at row(1)
MyTable.Rows(1)("Data") = "Terry Burns"
'Ok Lets Print out the rows modified
Debug.WriteLine("------- Modified ---------")
For Each r In MyTable.Rows
Debug.WriteLine(r("Data"))
Next
'Declare an array of rows
Dim OriginalRows() As DataRow
'Get them from the Table using select statement
OriginalRows = MyTable.Select(Nothing, Nothing,
DataViewRowState.OriginalRows)
Debug.WriteLine("------- These 'SHOULD' be the original
ows ---------")
For Each r In OriginalRows
Debug.WriteLine(r("Data"))
Next
Debug.WriteLine("------- Display the View value & the Row
value ---------")
Dim view As New DataView(MyTable, Nothing, Nothing,
DataViewRowState.OriginalRows)
For Each row As DataRowView In view
Debug.WriteLine(row("Data"), "DataRowView")
Debug.WriteLine(row.Row("Data"), "DataRow")
Next
------- Unmodified ---------
Item0
Item1
Item2
Item3
Item4
Item5
------- Modified ---------
Item0
Terry Burns
Item2
Item3
Item4
Item5
------- These 'SHOULD' be the original rows ---------
Item0
Terry Burns
Item2
Item3
Item4
Item5
------- Display the View value & the Row value ---------
DataRowView: Item0
DataRow: Item0
DataRowView: Item1
DataRow: Terry Burns
DataRowView: Item2
DataRow: Item2
DataRowView: Item3
DataRow: Item3
DataRowView: Item4
DataRow: Item4
DataRowView: Item5
DataRow: Item5
Notice that the DataRow itself returns "Terry Burns", while the DataRowView
itself return "Item1".
To get the DataTable.Select to work, try the following:
Debug.WriteLine("------- These 'ARE' be the original
Values ---------")
For Each r In OriginalRows
Debug.WriteLine(r("Data", DataRowVersion.Original))
Next
If that made any sense. ;-)
Hope this helps
Jay