在 DataTable 列中查找值
Look for a value in a DataTable column
我有一个 DataTable dt,它有一个 Column month,它看起来像这样。
month
yes
yes
我想检查列月份是否包含 "yes"。我在 Datatable dt 中没有主键。
像这样
if( dt.["month"] == "yes")
boolMonth = true;
假设,您要检查是否有任何行等于字符串值 "yes":
if(dt.Rows.Cast<DataRow>().Any( x => (string)x["month"] == "yes"))
boolMonth = true;
您也可以使用 LINQ to DataSet 之类的(假设 month
类型是 string
);
bool boolMonth = dt.AsEnumerable().
Any(row => row.Field<string>("month") == "yes");
我有一个 DataTable dt,它有一个 Column month,它看起来像这样。
month
yes
yes
我想检查列月份是否包含 "yes"。我在 Datatable dt 中没有主键。 像这样
if( dt.["month"] == "yes")
boolMonth = true;
假设,您要检查是否有任何行等于字符串值 "yes":
if(dt.Rows.Cast<DataRow>().Any( x => (string)x["month"] == "yes"))
boolMonth = true;
您也可以使用 LINQ to DataSet 之类的(假设 month
类型是 string
);
bool boolMonth = dt.AsEnumerable().
Any(row => row.Field<string>("month") == "yes");