Datatable Comparison not working - Datatype issues?

Hi everyone,

I have two datatables (‘dt_temp’ & ‘dt_comparison’) extracted from different Excel Files and want to compare them to find the (new) entries which only exist in dt_temp.

I tried using the Linq-Except Function based on several posts in this forum as:

dt_temp.AsEnumerable.Except(dt_comparison.asEnumerable,DataRowComparer.Default).CopyToDataTable()

As it did not work I merged the two tables and tried to remove all duplicate occurences with:

(From d In dt_temp.AsEnumerable()
Let cnt = dt_temp.AsEnumerable.Where(Function (r) d.ItemArray.SequenceEqual(r.ItemArray)).Count
Where cnt = 1
Select d).CopyToDataTable

However with both methods I received all values from dt_temp meaning the duplicates were not found.

I have checked manually and all values are the same - could this be a format or datatype issue? And if so, how can I check whether my datatable columns are the same format.

Thank you very much and best regards

Nico

@nicortak

Please try like this

(From d In dt_temp.AsEnumerable()
Let cnt = dt_Comparision.AsEnumerable.Where(Function (r) String.Join(",",d.ItemArray.Select(Function(x) x.ToString.Trim)).Equals(String.Join(",",r.ItemArray.Select(Function(x) x.ToString.Trim)))).Count
Where cnt = 1
Select d).CopyToDataTable

If you want new entries then ideally cnt = 0 I guess

cheers

1 Like

Works like a charm with your function and value 0!
Thank you very much I was about to lose hope… :smiley:

Thanks @Anil_G

1 Like

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