I want to convert the linq query results to datatable so that I can assign datatable to GridView to show it on asp page.
However I am not able to convert the results
First declare a new DataTable and add columns, in this :
DataTable dt = new DataTable();
dt.Columns.Add("FirstName");
dt.Columns.Add("LastName");
DataRow row = null;
Now I simply iterate through the query and fill a DataTable:
foreach (var rowObj in query)
{
row = dt.NewRow();
dt.Rows.Add(rowObj.FirstName, rowObj.LastName);
}