How to get the Original Row and the Modified Row of DataRowView using DataRowViewVersion

3k views Asked by At

I have a datatable that is filled from a database. I load a bindingsource with that table.

Sub LoadData()

Dim bsTemp As BindingSource = New BindingSource
bsTemp.DataSource = dtTemp

End Sub

I then have other code programmatically editing the values in the datatable. I NEVER call AcceptChanges() ..let me be clear NEVER.

I do call bsTem.EndEdit() and I also call that on my dtTemp.Row(x).EndEdit() Whenever I make a change to it.

So now all I want to do is compare the two rows (I know I can do this with a for each column but I am not wanting to do that.)

I would like to know how to make this work:

Dim modview As New DataView(dtTemp.Copy, "", "Id", DataViewRowState.ModifiedCurrent)

Dim origView As New DataView(dtTemp.Copy, "", "Id", DataViewRowState.ModifiedOriginal)

So I can then perform something like this:

    Dim rowComparer As DataRowComparer(Of DataRow) = DataRowComparer.Default

    IsEqual = rowComparer.Equals(origRow.Row, modRow.Row)

When I do this both views show the Modified data, one of them should only show me the Original unmodified Row.

I know I can do this [C# version]:

SomeDataRow[0, DataRowVersion.Original] //by index
SomeDataRow["ColumnName", DataRowVersion.Original]

But again tis works on a column by column basis - me being the iterator - and I see no reason to do that when the DataView supposedly has this built in . So what could I be doing wrong that I do not see the original version .

1

There are 1 answers

4
Steve On

The New DataView(..) does not determine which rows to copy, it only says what the state of the rows after they are in the view will have. Your first parameter says which rows dtTemp.Copy.

Since the copy method of a datatable is a copy of all rows, you might want to use something like the select method, which allows you to filter based on state.

dtTemp.Select("","",ModifiedOriginal)

EDIT:

There must be an issue with getting it that way. According to the example given from MSDN, it should work if you use the DataView.RowStateFilter. I tested it and it did work. I think the key is that the DataView controls what you see. If you look at the raw data through the DataRow, it is always current.