2015-04-07 92 views
0

我有一个DataTable dt,它有一个Column月,它看起来像这样。在DataTable列中查找值

month 
yes 
yes 

我想检查列的月份是否包含“是”。我在Datatable dt中没有主键。 像这样

if(dt.["month"] == "yes") 
boolMonth = true; 
+0

你想检查该列的_any_行有'是'吗?这个“月”列的类型是什么? –

回答

1

假设,要检查是否有任何行等于字符串值“是”:

if(dt.Rows.Cast<DataRow>().Any(x => (string)x["month"] == "yes")) 
boolMonth = true; 
1

您也可以使用LINQ to DataSet像(假设month型为string);

bool boolMonth = dt.AsEnumerable(). 
        Any(row => row.Field<string>("month") == "yes"); 
+0

我无法得到这个工作,是月是字符串。 – Akjell

+0

现在它的工作谢谢 – Akjell