Question : Get Data from  Datatable using LINQ

Hi

I need some data from a DataTable, I like to get this using LINQ

Somthing like this
[check code snippet]

But with this code I get the error message:
Could not find an implementation of the query pattern for source type 'System.Data.DataTable'.  'Where' not found.
1:
Var someData= from o in myDataTable where o.TestColumn1 == "SomeText" select o.TestColumn2;

Answer : Get Data from  Datatable using LINQ

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
// Iterate through the query to get the names
var query = from r in employeeDataTable.AsEnumerable()
            where r.Field<string>("LastName") == "Raman"
            select r.Field<string>(“FirstName”); 

foreach( var name in query )
{
    Console.Writeline(name);
}

===========================================================
// You can also turn it to a List<String>
List<String> query = (from r in employeeDataTable.AsEnumerable()
                      where r.Field<string>("LastName") == "Raman"
                      select r.Field<string>(“FirstName”)).ToList();
Random Solutions  
 
programming4us programming4us