Sun
Sun

Reputation: 157

Merge 2 Datatables

I have a Datatable D1 with

DataTable 1
------------
ID  Name1
1   S1
2   S2
4   S4


DataTable 2
------------
ID  Name2
1   D1
2   D2
3   D3

Result:

FinalTable
-----------
ID  Name1  Name2
1   S1     D1
2   S2     D2
3          D3
4   S4 

I tried the merge ds1.Merge(dt2, true, MissingSchemaAction.Add); This adds additional columns instead

Thanks Sun

Upvotes: 2

Views: 401

Answers (2)

billinkc
billinkc

Reputation: 61259

I believe you are looking to perform a FULL OUTER JOIN between two DataTables. "Full Outer Join of Two DataTables C# Code" seems to be a decent-enough example, otherwise you now know what search terms to use.

Upvotes: 1

JB King
JB King

Reputation: 11910

Try this SQL query

Select d1.id, d1.Name1, d2.Name2 from DataTable1 d1 join DataTable2 d2 on d1.id=d2.id

Join (SQL) would be a reference if you want one.

Upvotes: 0

Related Questions