I know how to do this in sql, but for c#..I cannot figure out how to make comparison of two datatables.
Let’s say:
1st datatable:
Name | Balance | Description
Smith | 1200 | Smith owes 600
Jordan| 4000 | Hi Jordan
Brooks| 5000 | I like my cat
Navaro| 6000 | description here
Gates | 9010 | omg
2nd datatable:
Name | Balance | Description
Smith | 1600 | Smith owes 600
Jordan| 4200 | I'M JORDAN
Clay | 9000 | Test description
Brooks| 5000 | I like my cat
I want to dump results of comparison to a simple html table.
Soooo…result should be like this:

Basically what I need is:
Show columns that are different and show data
Do not show record if all columns are identical
Show records that only exist in first datatable (just names)
Show records that only exist in second datatable (just names)
In sql, you could do something like merge, then pivot.
But in C#,
my findings:
I can use except, or intersect, but it returns one dattable. Is there any formatting options for an except\intersection functions?
I’m looking for an advice on how to achieve this the best way. (there’s about 100 columns in each datatable). All should be compared by name.
Here is the code you need to have in your .cs file…
(I’ve only created those two empty classes to avoid having in code
Dictionary<object, Dictionary<string, Tuple<object, object>>>but you can replace that if you prefer)And here is an example of how to build the table out of it in the .aspx file:
Styling the table as you wish shouldn’t be hard from here on.
So the main thing you have left is changing
GenerateTablesto some querying logic, or even in-line it insideGetDifferences.The finding algorithm can probably be perfected. It is currently O(m * n * k) in the worst case scenario, m and n being the number of rows in table1 and table2 respectively, and k being the number of columns. I can already think of ways to improve it by much, but I’ll leave those to you. This should get you started nice and good.
Just note that this algorithm assumes that the columns are equal between the two tables.
Let me know if there’s anything unclear about the solution, and good luck!