Original Rows

  • Thread starter Thread starter One Handed Man \( OHM - Terry Burns \)
  • Start date Start date
First Question.

1.) Has anyone 'actually' tried my code example ?, if so did you get the
same results ?

2.) If yes to 1.), then why does this not work. The select satement should
be able to generate a row set based on my criteria with a set of 'Original
Rows' IE Before modification took place.

3.) If What I have said in 2.) Is incorrect, why ?

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing
 
The original rows contain the original values. Remember that the DataTable
maintains several versions of the same row during modification before
AcceptChanges is called.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing
 
Hi Terry,

I tried all your code, even changed it so that should show you, however did
you tried yourt code I changed?

You persist in my opinion with the fact that an original row needs also to
have the original values and did not give any reason why?

That is not as I try to show you in the 10 different samples I sended you,
some changed from yours. When you had looked at the latest it should all
became clear.

Cor
 
Hi Cor,
You persist in my opinion with the fact that an original row needs also to
have the original values and did not give any reason why?
It does - the XML in the table proves it.

<diffgr:before>
<tblUsers diffgr:id="tblUsers1" msdata:rowOrder="0"
xmlns="http://www.tempuri.org/DS.xsd">
<UserID>1</UserID>
<FirstName>Emma</FirstName>
<LastName>Laity</LastName>
<Address>99 Highfield Road</Address>
<City>Arnam</City>
<State>Berkshire</State>
<ZIP>1DNT KNO</ZIP>
<Phone_x0020_Number>555 868333</Phone_x0020_Number>
</tblUsers>
</diffgr:before>

Yes, in fact the XML clearly shows that the table contains both versions of
the value for this row once modified. It has the 'before' attribute for the
original.

Below is the code I used to prove.

Private Sub btnShowRowState_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnShowRowState.Click

txtConsole.Text = Nothing
txtConsole.Text = ComboBox1.Text & vbCrLf & "--------------" &
vbCrLf
Dim r() As DataRow
Dim ir As DataRow

Ds1.Tables(0).DefaultView.RowStateFilter =
CType(ComboBox1.SelectedItem, State).MyState

r = Ds1.Tables(0).Select(Nothing, Nothing,
Ds1.Tables(0).DefaultView.RowStateFilter)

' METHOD 1 - Does Not Work
'For Each ir In r
'txtConsole.AppendText(ir("FirstName") &
(Microsoft.VisualBasic.vbCrLf))
'Next

'METHOD 2 - DOES work
Dim i As Integer
For i = 0 To Ds1.Tables(0).DefaultView.Count - 1

txtConsole.AppendText(Ds1.Tables(0).DefaultView.Item(i)("FirstName") &
(Microsoft.VisualBasic.vbCrLf))
Next
End Sub


--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing
 
Hi Terry,
It does - the XML in the table proves it.


It has and to get that you can use my latest sample I have sand yesterday.

(I showed you yesterday as well that serialize method to show you that it
has the old values however not in the original row.)

Cor
 
Cor,

I can get to it using my own methods as well as yours, you seem to be
missing the point here.

*The Point*
-------------
The Select method does 'not' return the original rows 'Which we have proved
are there' using the RowState Filter in the select statement.




--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing
 
Hi Terry,

The question is for me, is *selecting* the rows from the tables, selecting
the rows with the latest values using the rowstatusfilter to select or is it
selecting the rows with the originalvalues.

I stay with the first because I only use the rowstatefilter as a filter to
select the rows.

When you use the dataview it gets a different behaviour because than it is
not only filtering however as well giving the originalrows, and that for my
much more strange to see.

However which one is right, you go probably for the last, I for the first.

I hope you see my point now?

Cor
 
I think the Table.Select() method only deals with current rows. However, it
does seem to be able to distinguish, added rows etc, just not row versions,
it does not in fact support the full range of RowState enumerations.

However, when one Iterates through the Rows() Collection of the DefaultView,
the RowState Filter does report correctly. I still feel that the Select()
Method falls short of what it should be able to do, and at the least, this
should be documented as a limitation.

I think we understand each other , just coming from different angles. One
thing is that through this excercise I have learnt a little more that,
cannot be a bad thing

Thanks for taking the time out to discuss.


:)

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing
 
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
 
Terry,
Reading my other post I'm not sure how clear it is. ;-)

I tried your code below, your "problem" is the believe DataTable.Select
returns different DataRow objects based on the DataViewRowState parameter,
it does not.

My understanding is: There is only a single DataRow object for each row in a
DataTable, this single DataRow object, has multiple versions of the values.
Your code reinforces my believe.

So the code:
Debug.WriteLine("------- These 'SHOULD' be the original
ows ---------")
For Each r In MyTable.Select(Nothing, Nothing,
DataViewRowState.OriginalRows)
Debug.WriteLine(r("Data"))
Next

Returns all the DataRows that have Original Values in them, and then prints
the Current Values.

You need:
For Each r In MyTable.Select(Nothing, Nothing,
DataViewRowState.OriginalRows)
Debug.WriteLine(r("Data", DataRowVersion.Original))

Which returns all the DataRows that have Original values in them, and then
prints the Original values.

Hope this helps
Jay
 
Back
Top