将特定列从一个 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!
数据表格式:
some data
ColA|ColB|ColC
xxxx|xxxx|xxxx
some data
some data
代表其他与 ColA-ColC 无关的表数据
some data
represents other table data not related to ColA-ColC
如何将带有 xxxx 的 ColA-ColC 复制到新的 DataTable?
How can I copy ColA-ColC with xxxx to the new DataTable?
谢谢
推荐答案
复制整个表格并删除不需要的列.
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屋!
查看全文