将特定列从一个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);