Hi, how can I compare 2 datatables with multiple columns to get unmatched records? Previously I was using for each with a linq query but it takes too long for 100k over rows as there are many other validations as well.
Is there a way this can return a count with linq query?
For example:
DT1:
Col1 Country Col3 FirstName Col4 LastName
DT2:
Country FirstName Col3 LastName
I would like to check if the DT1 Country, FirstName and LastName matches the row in DT2.
Previous linq query in for each for DT1:
(DT2.Select(“[Country] = '”+row.item(“Country”).ToString+“’ And [FirstName] = '”+row.Item(“FirstName”).ToString+“’ And [LastName] = '”+row.Item(“LastName”).ToString+“'”)).Length > 0
When interrested on dtLeft rows which have a match in dtRight
(From d1 In dtLeft.AsEnumerable
Let arrCHK = arrLCols.Select(Function (x) d1(x)).toArray
Where dtRight.AsEnumerable.Any(Function (d2) arrRCols.Select(Function (y) d2(y)).SequenceEqual(arrCHK))
Select r=d1).CopyToDataTable
When interrested on dtLeft rows which have a NO match in dtRight
(From d1 In dtLeft.AsEnumerable
Let arrCHK = arrLCols.Select(Function (x) d1(x)).toArray
Where NOT dtRight.AsEnumerable.Any(Function (d2) arrRCols.Select(Function (y) d2(y)).SequenceEqual(arrCHK))
Select r=d1).CopyToDataTable