Using LINQ's .Any() on a DataTable
I have a datatable loaded up with some records and I am then pulling a
query from another file and want to check if the ID that I pull in this
query exists in my datatable.
foreach (var item in records)
{
bool hasit = dt.AsEnumerable().Any(p => p.Field<string>(0) == item.ID);
if (!hasit)
{
//Logic
}
}
I'm using that .Any() function and expecting it to return true if there is
an ID in the first field of the datatable that matches the id in the
records collection. It continually returns false though, am I missing
something? Is there a better way to do this?
No comments:
Post a Comment