检查DataRow数组中是否存在值
在我的应用程序中,我正在使用过滤器表达式过滤数据表,并获取匹配条件的DataRow.现在我想检查DataRow数组的任何行中是否存在特定列的值.
In my application i am filtering a datatable using a filter expression and am getting a DataRow which matches the condition.Now i want to check if the value of particular column exists in any row of DataRow array.
代码:
string FilterCond1 = "id=" + getId;
DataRow[] myrow = DataTable.Select(FilterCond1);
if (myrow.Length > 0)
{
//check for size=28 in DataRow[]
}
else
{
}
我在数据表 DataTable
中有 size 列,我想检查DataRow数组的任何行中是否有值 28 .列 size
.如何处理?
I have column size in the datatable DataTable
and i want to check if any row of the DataRow array has a value 28 in the column size
.How can i go about it?
尝试一下
string FilterCond1 = "id=" + getId;
DataRow[] myrow = DataTable.Select(FilterCond1);
if (myrow.Length > 0)
{
for(int i = 0; i < myrow.Length; i ++)
{
if(myrow[i]["size"].ToString() == "28")
{
// YOUR CODE HERE
}
}
}
else
{
}
编辑
只需将条件添加到您的过滤器中即可.
Just add the condition to your filter.
string FilterCond1 = "id=" + getId + " AND size=28";
那么您就不需要 if(myrow [i] ["size"].ToString()=="28")
,因为您知道数组中的行就是您所需要的想要.
Then you don't need the if(myrow[i]["size"].ToString() == "28")
as you know the rows in the array are the one you want.