I want to perform a LINQ query on a datatable called Records and check if a record exists. If it exists, I want to find out the row which it is in. How might I go about doing this?
I wanted to do a .where on my datatable after adding the system.linq namespace but the method didnt seem to exist. Please advise
P.S : Am using c# in vs 2010
DataTable is not default uses Enumerable. you have to convert to
var result = from p in dataTable.AsEnumerable()
where p.Field("ID") == 2
select p.Field("Name");
if(result.Any())
{
//do your work
}
read this article for
http://blogs.msdn.com/b/adonet/archive/2007/01/26/querying-datasets-introduction-to-linq-to-dataset.aspx
getting understanding your to use Field<T>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With