Comaparing Datatables (multiple columns)

Instead of looping thru data tables, you can achieve with two LINQ queries.

One is for matched rows
Another is for unmatched rows

The following LINQ queries are in c#. (The syntax in VB.Net is almost same. Just remove the semicolon at the end)

            var matched = from table1 in dt1.AsEnumerable()
                          join table2 in dt2.AsEnumerable() on table1.Field<String>("User") equals table2.Field<String>("User")
                          where table1.Field<String>("Client") == table2.Field<String>("Client") && table1.Field<string>("Date") == table2.Field<string>("Date")
                          select table1;

            var unmatched = from table1 in dt1.AsEnumerable()
                                           where !matched.Contains(table1)
                                           select table1;

Output:
image

Regards,
Karthik Byggari

5 Likes