Compare two DataTables to determine rows in one but not the other

Assuming you have an ID column which is of an appropriate type (i.e. gives a hashcode and implements equality) – string in this example, which is slightly pseudocode because I’m not that familiar with DataTables and don’t have time to look it all up just now 🙂

IEnumerable<string> idsInA = tableA.AsEnumerable().Select(row => (string)row["ID"]);
IEnumerable<string> idsInB = tableB.AsEnumerable().Select(row => (string)row["ID"]);
IEnumerable<string> bNotA = idsInB.Except(idsInA);

Leave a Comment