Possible Duplicate:
C#, how to compare two datatables A + B, how to show rows which are in B but not in A
I need to compare two datatables in c# to find the differences. The two datatables have the same schema. What is the best way to do it? Can it be done using linq queries? If yes, How?
You could use LINQ to join the two
DataTableobjects, matching every column. Then take theIQueryableand find all the rows in the first twoDataTableobjects which are not in theIQueryable.Example:
The code above should work, though I did not test it.
You could also check out LINQ query on a DataTable which has some useful information on using LINQ with DataTables.
I also find the LINQ samples to be helpful when writting LINQ.