المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Merging or adding 2 different DataTables into Single DataTable



C# Programming
01-12-2010, 02:20 PM
Hi All,

I want to merge 2 tables.
These 2 tables have different columns but the no.of records same.

DataTable dt1, DataTable dt2;

dt1: contains records like below
===============================
colA colB colC
----------------
a1 b1 c1
a2 b2 c2
a3 b3 c3

dt2: contains records like below
===============================
colD colE colF
----------------
d1 e1 f1
d2 e2 f2
d3 e3 f3


I have to make these two table into one single table like below
Required DataTable

colA colB colC colD colE colF
--------------------------------
a1 b1 c1 d1 e1 f1
a2 b2 c2 d2 e2 f2
a3 b3 c3 d3 e3 f3

How can we do that?

I approached like, taken a DataTable and added columns of dt1 and dt2 the this table. then added the records to main DataTable through looping each record of dt1 and dt2.

Is there any other way do this with out using loop statements.
Both the tables are different, they don't have any relation between them, only the no.of records were same.

Please suggest me how to this.

Thanks in advance.