检查每一行的列中的值 [英] Checking value in column foreach row
问题描述
DataTable(dt)存储了carID的检索值并进行存储,因此它在DataTable中存储了3行,我还有另一个名为dt2的DataTable也存储了carID的表并进行了存储,我正在尝试遍历dt看看dt2中的任何行中是否存在存储在dt中的任何carID,这是我到目前为止所拥有的:
The DataTable (dt) stores the retrieved values of carID's and makes so it stores like 3 rows within the DataTable, I also have another DataTable called dt2 which also stores carID's and makes, I am trying to loop through each row in the dt to see if any carID stored in the dt exists in any of the rows in dt2, here is what I have so far:
DataTable dt = w.getUserCars(userID);
foreach (DataRow dr in dt.Rows)
{
string carID = dr["carID"].ToString();
}
我该怎么做?
推荐答案
您应该可以使用 DataTable.Select()
方法实现此目的。您走在正确的轨道上。您只需添加方法即可在 dt2
中找到 Row
。
You should be able to achieve this using DataTable.Select()
method. You are on the right track. You just need to add the method to find the Row
(s) in dt2
.
DataTable dt = w.getUserCars(userID);
DataRow[] foundRows;
foreach (DataRow dr in dt.Rows)
{
string carID = dr["carID"].ToString();
foundRows = dt2.Select("carID = " + carID);
// do stuff here with foundRows
foreach (DataRow r in foundRows)
{
r.Delete();
}
}
这篇关于检查每一行的列中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!