Datatable Concatination
-
Hi, I have 3 different Datatable with different coloumns, i want to concatinate with 3 tables into a single table , but i dont want to merge how can achieve this, datatable1 datatable2 datatable3 1st table 5 columns 2nd table 7 columns 3rd table 3 coloumn for (i=0 to 3) { for(j=0 to datatable1.columns.count-1) { dr1[j]=j; } for(j=0 to datatable2.columns.count-1) { dr2[j]=j; } for(j=0 to datatable3.columns.count-1) { dr3[j]=j; } } So finally i want to concatinate with the 3 table with 3 rows... note: I dont want to merge.. How to do this... Plz answer me... thanks in Advance.. kannak......
kannak
-
Hi, I have 3 different Datatable with different coloumns, i want to concatinate with 3 tables into a single table , but i dont want to merge how can achieve this, datatable1 datatable2 datatable3 1st table 5 columns 2nd table 7 columns 3rd table 3 coloumn for (i=0 to 3) { for(j=0 to datatable1.columns.count-1) { dr1[j]=j; } for(j=0 to datatable2.columns.count-1) { dr2[j]=j; } for(j=0 to datatable3.columns.count-1) { dr3[j]=j; } } So finally i want to concatinate with the 3 table with 3 rows... note: I dont want to merge.. How to do this... Plz answer me... thanks in Advance.. kannak......
kannak
Use this :
DataTable dt = datatable1.clone();
foreach(DataColumn dc in datatable2.Columns)
{
DataColumn dc1 = new DataColumn(dc.Caption,dc.DataType);
dt.Columns.add(dc1);
}foreach(DataColumn dc in datatable3.Columns)
{
DataColumn dc1 = new DataColumn(dc.Caption,dc.DataType);
dt.Columns.add(dc1);
}Now to merge the data you need to
for(i=0;i
Finally
dt.Rows.Add(drNew)
You can also make it more cleaner. Also change it according to your need.
Hope it works :) :) :)Abhishek Sur
My Latest Articles
**Create CLR objects in SQL Server 2005
C# Uncommon Keywords
Read/Write Excel using OleDB**Don't forget to click "Good Answer" if you like to.
modified on Friday, September 18, 2009 1:49 PM