I am using Northwind Customers Table where I fill the dataset and get the datatable.
I am trying to use dynamic linq and want to select columnName dynamically
var qry = MyDataTable.AsEnumerable().AsQueryable().Select("new(Country)");
Right now I have hard coded country but even then I get this error
No property or field 'Country' exists in type 'datarow'
I would like to eventually change this query to take the column name dynamically.
Please help!!! thanks.
The important hint is here (in bold):
The extension method
AsEnumerable
of theDataTable
class returns anIEnumerable<T>
where T has the typeDataRow
. Now theSelect
method of Dynamic LINQ wants to work with this typeDataRow
which hasn't a propertyCountry
of course.You could try this instead:
it
now represents a variable of typeDataRow
and you can use methods of this type and perhaps also the indexer in my example above. (Dynamic LINQ supports accessing array elements by an integer index, but I am not sure though if accessing an indexer with a string key will work.)