views:

37

answers:

2

I have filled my dataset from multiple xml files in C#.Net. As a result I have a dataset which contains multiple DataTables in it. All of them are having two columns each namely "ID" and "Name". These data tables can contain rows for same ids actoss all the tables.

For Example:

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

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

My objective is to combine all the data into one datatable as shown below

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

Is there any way to achieve this? May be using relations, DataViews... just guessing.

Thanks in advance..

+3  A: 

Try DataTable.Merge.

Noel Abrahams
Might work if you can use "Name1" and "Name2" in the src tables.
Henk Holterman
Will it match id's when two tables will be merged?
Anil
@Henk: I used DataTable.Merge but it adds additional rows for second table. it does not match the ids and maintains the row count in first table.
Anil
+2  A: 

easiest way is Merge function of datatable and you can also use Merge to combining results of two datasets also , see here at MSDN

saurabh
@Saurabh: I used DataTable.Merge but it adds additional rows for second table. it does not match the ids and maintains the row count in first table.
Anil