将特定列从一个DataTable复制到另一个 [英] Copy specific columns from one DataTable to another
本文介绍了将特定列从一个DataTable复制到另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在DataTable中读取一些数据(来自excel文件),现在我要过滤并将特定列复制到另一个!
Have some read in data (from excel file) in a DataTable and now I want to filter this and copy only specific columns to the other one!
dataTable格式:
dataTable format:
some data
ColA|ColB|ColC
xxxx|xxxx|xxxx
some data
某些数据
表示其他表数据与ColA-ColC相关
some data
represents other table data not related to ColA-ColC
如何将ColA-ColC与xxxx复制到新的DataTable?
How can I copy ColA-ColC with xxxx to the new DataTable?
Thx
推荐答案
复制整个表格并删除列不要。
Copy the whole table and remove the columns you don't want.
DataTable copyDataTable;
copyDataTable = table.Copy();
copyDataTable.Columns.Remove("ColB");
或
int columnIndex = 1;//this will remove the second column
DataTable copyDataTable;
copyDataTable = table.Copy();
copyDataTable.Columns.RemoveAt(columnIndex);
这篇关于将特定列从一个DataTable复制到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文