Have a Linq query as following which works:
from row in myDataTable.AsEnumerable() select row.Field<string>("myDataColumn")
Now try to make it work with any column data type (not just string). Tried the following:
from row in myDataTable.AsEnumerable() select row.Field<myDataTable.Columns["myDataColumn"].DataType>("myDataColumn")
But it doesn’t work.
So is there a way to make the data type dynamic in this particular Linq query?
The
Fieldproperty is designed for getting the value when you know the type at compile time. When you don’t just use the indexer:This will return the value as an
object.