Reputation: 109
I have a DataTable dt that have a Column month it looks like this.
month
yes
yes
I want to check if the column month contains "yes". I don't have a primary key in the Datatable dt. Something like this
if( dt.["month"] == "yes")
boolMonth = true;
Upvotes: 0
Views: 60
Reputation: 98740
Also you can use LINQ to DataSet like (assume month
type is string
);
bool boolMonth = dt.AsEnumerable().
Any(row => row.Field<string>("month") == "yes");
Upvotes: 1
Reputation: 45947
assumed, you want to check if any row equals the string value "yes":
if(dt.Rows.Cast<DataRow>().Any( x => (string)x["month"] == "yes"))
boolMonth = true;
Upvotes: 1