2 回答
TA贡献1874条经验 获得超12个赞
您可以为此使用 linq 而不是 DataView
List<int> filter = new List<int>()
{
75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,281,303,405,406,493,599,601,606,610,626,630,639,640,647,648,651,662,664,671,672,680,689,697,701,703,706,709,712,717,718,724,735,740,741,743,744,767,768,769,770,775,780,791,799,800,801,802,803,805,806,807,808,810,811,812,815,816,817,818,820,836,837,873,874,875,879,881,895,896,897,902,903,904
};
DataTable output = dt.AsEnumerable().Where((row,index) => !filter.Contains(index)).CopyToDataTable();
希望这能回答你的问题
TA贡献1811条经验 获得超4个赞
// list of values to be filtered
List<int> filter = new List<int>()
{
75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,281,303,405,406,493,599,601,606,610,626,630,639,640,647,648,651,662,664,671,672,680,689,697,701,703,706,709,712,717,718,724,735,740,741,743,744,767,768,769,770,775,780,791,799,800,801,802,803,805,806,807,808,810,811,812,815,816,817,818,820,836,837,873,874,875,879,881,895,896,897,902,903,904
};
// LINQ statement to do filtering
IEnumerable<DataRow> unmatchingRows = from DataRow row in dt.Rows
where !filter.Contains((int)row[0])
select row;
// add to a new datatable
DataTable output = dt.Clone();
foreach (DataRow item in unmatchingRows)
{
output.ImportRow(item);
}
- 2 回答
- 0 关注
- 154 浏览
添加回答
举报