Click here to Skip to main content
15,904,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
i need to copy data from different columns image1,image2,image3etc in a datatable. onto a single column image1 in another datatable using c#.can anybody help me please.god bless you
Posted
Updated 29-Sep-13 20:41pm
v2
Comments
[no name] 30-Sep-13 2:54am    
not clear.. keep it simple

you mean merge many into one..?
faizel s 30-Sep-13 2:58am    
i have several columns like image1,image2,image3 in one datatable.i want to copy copy data from these columns onto single column in another datatable.did you understand what i am saying?god bless you

using this following code you can select records from one datatable and copy to other

DataTable dt2 = dt1.Select("(Column1 = 'put condition')").CopyToDataTable();
 
Share this answer
 
Comments
faizel s 30-Sep-13 3:51am    
what should we put in the place of condition,
sahabiswarup 30-Sep-13 5:09am    
suppose there is one column in dt1 named "Type"; you want to sort or fetch data from dt1 as "Type" basis.

DataTable dt2 = dt1.Select("(Type = 'image')").CopyToDataTable();

so all image type of records will be copied to the new datatable ie dt2.
Dear Faizel,

Try the following code, make sure you add column in dt2 datatable.

C#
foreach (DataRow dr in dt1.Rows) {
	dt2.Rows.Add(dr("image1").ToString() + dr("image2").ToString() + dr("image2").ToString());

}


Regards,
Bluesathish
 
Share this answer
 
What you need to do is just loop through all the row of the table and add all of your column to the single column of the new data table like this.

C#
foreach (DataRow dr in DataTableOld.Rows) {
	NewDataTable.Rows.Add(dr("Col1").ToString() + dr("Col2").ToString()
 
}


-SG
 
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