I have 2 data tables DT1 and DT2 and my goal is to match address from these 2 excel files (data tables).
Logic need to be build in this order:
Filter DT1 with COUNTRY = USA → Copy EID (one by one) and search it in DT2 (Employee ID) → If found → Check if Country from DT1 (“USA”) = COUNTRY from DT2 (“United States”).
If matches, then pick POSTAL code from DT1 and search it in DT2 of Postal Code → Likewise, next drill down for STATE, CITY, ADDRESS1, ADDRESS2, ADDRESS3 matching from DT2.
Thanks for your reply. I have already applied this logic - for each loop.
My logic:
For each row in DT1:
CurrentRow in DT1
For each row in DT2:
CurrentRow2 in DT2
IF:
CurrentRow(“EID”).ToString = CurrentRow2(“Employee ID”).ToString
and then nested if’s, I have applied.
And also, if it doesn’t matches the address I need to store them all unmatched addresses in 1 excel.
Yes, you can store unmatched rows in single DataTable variable jst like matched rows by using LINQs except method:
Dim dt1USA = DT1.AsEnumerable().Where(Function(r) r("COUNTRY").ToString.Trim.ToUpper = "USA")
Dim unmatched = dt1USA.Except(matched.AsEnumerable(), DataRowComparer.Default)
If unmatched.Any Then
Dim unmatchedDT = unmatched.CopyToDataTable()
Else
Dim unmatchedDT = DT1.Clone() 'returns an empty table with headers if no unmatched rows
End If
This gives you all unmatched rows in one variable unmatchedDT