无法基于另一个DataTable从DataTable中删除行

时间:2014-10-31 12:03:35

标签: c# datatable row

我有两个DataTable

distinct

+-------+-------+
| host  | count |
+-------+-------+
| comp1 |     2 |
+-------+-------+
| comp2 |     3 |
+-------+-------+
| comp3 |     2 |
+-------+-------+

t

+----+-------+
| id |  host |
+----+-------+
| 1  | comp1 |
+----+-------+
| 2  | comp2 |
+----+-------+
| 3  | comp1 |
+----+-------+
| 4  | comp3 |
+----+-------+
| 5  | comp1 |
+----+-------+
| 6  | comp3 |
+----+-------+

我想删除t中包含3count列中distinct小于for (int i = 0; i < distinct.Rows.Count; i++) { if (Convert.ToInt32(distinct.Rows[i][1]) < 3) { foreach (DataRow row in t.Select()) { if (row[1].ToString() == distinct.Rows[i][0].ToString()) { row.Delete(); } } } } 的计算机名的所有行。代码:

t

但它什么都没做。如果我在上面的代码之前和之后比较{{1}}的内容,它就是一样的。我在这里错过了什么?

1 个答案:

答案 0 :(得分:0)