How to use LINQ on DataTable-object?

  • Thread starter Thread starter K Viltersten
  • Start date Start date
K

K Viltersten

I recieved a DataTable oject and i wished to
obtain a list of the captions. So, i went
like normal people do:

from e in dataTable.Columns
select e.Caption;

However, i run into problems due to Columns
not being LINQ-queryble. I've tried to use
AsQueryble and GetEnumerator. However, to no
avail. Any suggestions?
 
K Viltersten said:
I recieved a DataTable oject and i wished to
obtain a list of the captions. So, i went like normal people do:

from e in dataTable.Columns
select e.Caption;

However, i run into problems due to Columns not being LINQ-queryble. I've
tried to use
AsQueryble and GetEnumerator. However, to no
avail. Any suggestions?

var query = from d in table1.AsEnumerable()

where d.Field<bool>("IsDirty")

|| d.Field<bool>("Delete")

select d;

foreach (var row in query)

{

WasOneDirty = row.Field<bool>("IsDirty");

IsThisOneDelete = row.Field<bool>("Delete");

IsThisOneNew = row.Field<bool>("IsNew");

var ID = row.Field<short>("ID");

Other code is <snipped>.

}





__________ Information from ESET NOD32 Antivirus, version of virus signature database 4518 (20091017) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
Back
Top