将数据表中的所有列复制到另一个数据表中的单个列 [英] copying all columns in a datatable to single column in another datatable

查看:83
本文介绍了将数据表中的所有列复制到另一个数据表中的单个列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要从数据表中的不同列image1,image2,image3etc复制数据。使用c#。在另一个数据表中的单个列image1上使用c#.can任何人帮助我。请使用以下代码祝福你

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

推荐答案

您可以从一个数据表中选择记录并复制到另一个



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

DataTable dt2 = dt1.Select("(Column1 = 'put condition')").CopyToDataTable();


亲爱的Faizel,



请尝试以下代码,确保添加dt2 datatable中的列。



Dear Faizel,

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

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

}





问候,

Bluesathish



Regards,
Bluesathish

你需要做的就是循环遍历表的所有行,并将所有列添加到新数据表的单个列中。



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.

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





-SG



-SG


这篇关于将数据表中的所有列复制到另一个数据表中的单个列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆