Check if values have been modified in DataTable

Hi everyone, hope you are doing well.
I have a problem with comparing two Data Tables:
example: I am having 2 DataTables, dtprevious and dtnew, I want to compare the DataTAbles in such a way to see if there’s been any modification with the data
this is dtprevious

this is dtnew

As you can see in dtnew there is a slight modification in the name David, City Sydney and name Mash.
I want to write only the modified values in new sheet.
How can I do this?..Plz help
Thanks in advance
P.S: this is only sample data. I have data in thousands of rows with long names as well


If the both datatable size (number of rows and columns) is same, the following will work.

dt1.AsEnumerable.Zip(dt2.AsEnumerable,Function(r1,r2) dt1.Clone.LoadDataRow(r1.ItemArray.Zip(r2.ItemArray,Function(v1,v2) if (v1.ToString=v2.ToString,"",v2.ToString)).ToArray(),False)).CopyToDataTable (2.9 KB)


DataTable size can vary, even the values cell position is not fixed.


Can you share input sample and expected output as file?


Previous File:
previous File.xlsx (9.0 KB)

Latest File:
Latest File.xlsx (9.0 KB)

After Comparing the Previous and Latest File, modified values are written in results file.

Results File:
result.xlsx (8.3 KB)


How about the following expression?

dtResult1 = dtPrevious.AsEnumerable.Where(Function(r)  not dtLatest.AsEnumerable.Any(Function(r2) DataRowComparer.Default.Equals(r,r2))).CopyToDataTable

dtResult2 = dtLatest.AsEnumerable.Where(Function(r)  not dtPrevious.AsEnumerable.Any(Function(r2) DataRowComparer.Default.Equals(r,r2))).CopyToDataTable

I suppose if we need to output data from previousFile, do we also need to output Ferrari Spain, don’t we? (21.5 KB)


Nope no need, only the values which are modified or changed.


How about the following? (21.5 KB)

However I think there might be some cases we cannot recognize whether it’s change or deletion.


Yup it worked, Thankyou

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.