如何删除数据集的列?数据

2023-09-04 05:30:29 作者:你得宠着我

我如何可以删除数据集的列?

是否有将做到这一点对我来说这样的方法:

  rh.dsDetail = ds.Tables [0] .Columns.Remove(
 

或许是这样的:

  rh.dsDetail = ds.Tables [0] .Columns.Remove(ds.Tables [0] .Columns [1],ds.Tables [0] .Columns [2] )
 

解决方案

首先,数据表中的列,而不是一个数据集。

excel 2016 如何删除一列数据后面的单位

如果你想摆脱他们,然后:

  table.Columns.Clear();
 

否则,如果您有索引:

  table.Columns.RemoveAt(0);
 

应该做的工作,如果你有列索引。请注意,如果你删除列0,则该数字将洗牌(所以你可能需要做相反的顺序)。

另外,你可能想通过名称删除:

  table.Columns.Remove(富);
 

How can I delete a column of a Dataset?

Is there a method that will do this for me like this:

rh.dsDetail = ds.Tables[0].Columns.Remove(

Or maybe like this:

rh.dsDetail = ds.Tables[0].Columns.Remove( ds.Tables[0].Columns[1],ds.Tables[0].Columns[2])

解决方案

First, a DataTable has columns, not a data-set.

If you want to get rid of them, then:

table.Columns.Clear();

otherwise, if you have the index:

table.Columns.RemoveAt(0);

should do the job if you have the column index. Note that if you remove column 0, then the numbers will shuffle (so you might need to do in reverse order).

Alternatively, you may want to remove by name:

table.Columns.Remove("Foo");