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
dt1
this is dtprevious

dt2
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

Hi,

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

Sample20221121-4.zip (2.9 KB)

Regards,

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

HI,

Can you share input sample and expected output as file?

Regards,

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)

HI,

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?

Sample20221121-7.zip (21.5 KB)

Regards,

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

Hi,

How about the following?

Sample20221121-7v2.zip (21.5 KB)

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

Regards,

Yup it worked, Thankyou

1 Like

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