Click here to Skip to main content
16,016,022 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
i have more than one datatable in a dataset how can i combine them into single datatable for eg

table 1 data is
A B C
1 2 3
4 5 6
7 8 9

table 2

A1 E F
1 3 4
4 5 10

now finally i want the table 1 in dataset should be

A B C E F
1 2 3 3 4
4 5 6 5 10
7 8 9
Posted

WAY #1:
Steps:
1. Have a new DataTable (DataTable dt = new DataTable();).
2. Add needed columns to it using dt.Columns.Add() method
3. Loop through both datatables above one by one
4. Copy the rows to new table - if it already exists then append it or else add a new row.

WAY #2:
Use Merge method: DataTable.Merge Method[^]

Try!
 
Share this answer
 
v2
Comments
lakshmichawala 17-May-11 3:03am    
how to create columns to new datatable
Sandeep Mewara 17-May-11 3:11am    
Updated reply. Now try!
In query you can combine it into one.

SELECT col1, col2, col3 from Table1
union
SELECT col1, col2, col3 from Table2


Hope this can help you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900