.net - Comparing datatable values between row for change detection -
my goal detect & write information value changed before update row database.
for example, have 2 datatables same column structure: beforeedit , afteredit. in case, have 1 row each datatables.
for integer = 0 beforeedit.columns.count - 1 if beforeedit(0).item(i) <> afteredit(0).item(i) 'storing log column have changed end if next is there better approach task?
thanks in advance
you don't need 2 datatables. each datarow maintains 2 copies of data. rowstate property of datarow can tell whether has changed or not. unchanged if no change has occurred , modified otherwise. can use code determine if , changes have occurred in datarow:
private sub logrecordchanges(row datarow) if row.rowstate = datarowstate.unchanged console.writeline("no changes row.") else each column datacolumn in row.table.columns dim currentvalue = row(column, datarowversion.current) dim originalvalue = row(column, datarowversion.original) if currentvalue.equals(originalvalue) console.writeline($"no changes column '{column.columnname}'.") else console.writeline($"column '{column.columnname}' changed '{originalvalue}' '{currentvalue}'.") end if next end if end sub
Comments
Post a Comment