Search code examples
c#excelmergedatatable

Merge colums of two DataTables in C#.net


If dt1 contains Column["Item"] and dt2 also contains Column["Item"] then, dt3 will have only one Column["Item"]. If both of they have "Burger" as an item then overwrite with one and if uncommon then add in a new row.

I've tried to do it with tabel3.Clone(table1) and table3.merge(table2). It shows me this:

A:Part 1

A:Part 2

Please notice that the common elements of tb1 and tb2 is there and all the elements of tb2.

But when I'm just using tb1.merge(tb2) and tb3=tb1, it is viewing me this: B: Part 1

B: Part 2

Notice, all the elements of tb1 is viewing and both of the table merges but the elements of tb2 is not viewing.


Solution

  • Have you looked at using linq to query/write?

    see: http://msdn.microsoft.com/en-us/library/dd920313%28v=office.12%29.aspx

    along with lots of questions here on stack overflow.