Hopefully this is relatively simple. After I perform a LINQ query on a DataTable I want to put the results in a another DataTable which I plan to create dynamically. What I need is to find the name of th column titles in the LINQ Query reults collection.
EDIT: The LINQ Query
var results= from a in dt.AsEnumerable()
where a.Field<int>("ID") == i
select new
{
ID = a.Field<int>("ID"),
a = a.Field<double>("A"),
b = a.Field<double>("B")
};
I am basically trying to return – “ID”, “a”, and “b”.
Really hope that makes sense!
Since query results set is a set of anonymous type items you can NOT do anything in terms of DataTable and DataColumn/Rows… But you can retrieve names using reflection since each column will be represented as public property of the anonymous type:
This would return: