Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
i have a two datatable(dt1 and dt2)
column 1 to 5 in dt1
and i want to copy few records from first datatable to second datatable(copy column 1,2,3 in dt2)
 
how?
 
thanks
 

How I copy data table specifiy columns to another Datat able?
 

In C# , I m using one datatable concept, In that datatable had 7 columns,
Now I want to copy first 5 Coulmns for first New Datatable How do I this ?
 
Source Table Name - Days
 
Date | Day1 | Slot 1 | Day 2 | Slot 2 | Day 3 | Slot 3
 
9:00 AM | Invite | A,0 | Invite | B,0 | Invite | C,0
9:20 AM | Invite | A,1 | Invite | B,1 | Invite | C,1
 

New Datable Name : dtInternational
 
Date | Day1 | Slot 1 | Day 2 | Slot 2
 
9:00 AM | Invite | A,0 | Invite | B,0
9:20 AM | Invite | A,1 | Invite | B,1
Posted 3-Oct-12 22:06pm
Edited 3-Oct-12 22:26pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hi,
 
Use the below query
 
INSERT INTO dt2 VALUES as
                 SELECT col1,col2,col3 FROM dt1
 
Please make sure that data type and length of subsequent columns are same.
 
You can also specify column name in table 2 on which column you want to insert data.
 
as below
 
INSERT INTO dt2<columns name in which you want to insert the data.> VALUES as
                 SELECT col1,col2,col3 FROM dt1
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

i friend,
 
Apply a select query for the data table, you will get the selected rows from one datatable to another datatable.
 
http://www.dotnetperls.com/datatable-select[^]
 
http://msdn.microsoft.com/en-us/library/det4aw50.aspx[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

hi ,
With below query you can write the column names also ans where condition also.
 
DataRow[] rows = datatable.Select('TOP 5');
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

then what is your problem this is not proper question .u did not explain your tables structure and condition .
  Permalink  

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

  Print Answers RSS
0 DamithSL 400
1 Maciej Los 222
2 OriginalGriff 213
3 BillWoodruff 130
4 Zoltán Zörgő 85
0 OriginalGriff 7,969
1 DamithSL 6,139
2 Sergey Alexandrovich Kryukov 5,449
3 Maciej Los 5,309
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 4 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100