Reputation: 755
How can check if the value exist in datatable column (int)
For example, I search if "9" exist in the column named "entryHour".
bool exists = listAgenda.AsEnumerable().Where(c => c.Field<string>("entryHour").Equals(9)).Count() > 0;
Thanks for your help.
Upvotes: 0
Views: 1186
Reputation: 36393
It looks like you are mixing between a string and int values. You need to compare apples with apples.
bool exists = listAgenda.AsEnumerable().Any(c => c.Field<string>("entryHour") == "9");
Upvotes: 0
Reputation: 5990
If you have integer type field in database then try this
bool exists = listAgenda.AsEnumerable().Any(c => c.Field<int>("entryHour") == 9));
But if you have string type then need to cast into integer first
bool exists = listAgenda.AsEnumerable().Any(c => int.Parse(c.Field<string>("entryHour")) == 9));
Upvotes: 3