I am having real troubles trying to compare my original values and the changed values in a DataTable. I use the DataViewRowState enumeration to filter the appropriate values. I do see that the values are different (when comparing the before/after) in their respective DataView, but when I try to copy the set of values to a new DataTable or new DataView, or whatever object, I only get the modified value. Can someone PLEASE help me with this problem, provide me with any tips to steer me in the right direction, anything at all. This is killing me here.
I've provided my code below for your review. Thanks a ton!!
regards,
Brian
The problem with doing something right the first time is that nobody appreciates how difficult it was.
I've provided my code below for your review. Thanks a ton!!
Code:
Private Sub PrintDifferences(ByVal dv As DataView, ByVal label As String)
dv.RowStateFilter = DataViewRowState.OriginalRows
Dim dvOrig As IEnumerator = dv.GetEnumerator
Dim dtOriginal As New DataTable()
dtOriginal = dv.Table.Clone
Dim row As DataRow
While dvOrig.MoveNext
row = dtOriginal.NewRow()
row("LINE_ID") = CType(dvOrig.Current, DataRowView).Row.Item("LINE_ID")
row("ITEM_VALUE") = CType(dvOrig.Current, DataRowView).Row.Item("ITEM_VALUE")
dtOriginal.Rows.Add(row)
End While
dtOriginal.AcceptChanges()
dv.RowStateFilter = DataViewRowState.ModifiedCurrent
Dim dvMod As IEnumerator = dv.GetEnumerator
Dim dtModified As New DataTable()
dtModified = dv.Table.Clone
While dvMod.MoveNext
row = dtModified.NewRow()
row("LINE_ID") = CType(dvMod.Current, DataRowView).Row.Item("LINE_ID")
row("ITEM_VALUE") = CType(dvMod.Current, DataRowView).Row.Item("ITEM_VALUE")
dtModified.Rows.Add(row)
End While
dtModified.AcceptChanges()
Console.WriteLine(ControlChars.Cr + label)
Dim i As Integer
For i = 0 To dtModified.Rows.Count - 1
Dim original As Long = CType(dtOriginal.Rows(i)("ITEM_VALUE"), Long)
Dim modified As Long = CType(dtModified.Rows(i)("ITEM_VALUE"), Long)
Dim diff As Long = Math.Abs(original - modified)
If diff > 0 Then
Console.Write("LINE ID ")
Console.Write(dtModified.Rows(i)("LINE_ID"))
Console.Write(" = ")
Console.WriteLine(diff.ToString + " (DIFF)")
End If
Next i
Console.WriteLine(ControlChars.Cr + "======================")
End Sub
regards,
Brian
The problem with doing something right the first time is that nobody appreciates how difficult it was.