Since the query returns an IEnumerable of Type DataRow, you have to specify what to insert into the datatable, in this case DataRow.
DataTable dt = query.CopyToDataTable<DataRow>();
If you used
var query = //linq query of what you need for new datatable....
DataTable dt = query.CopyToDataTable();
Your table name is dt so select what you need from the original dt
var query = from c in db.something
where c.othersomething == "onlyyouknow"
orderby c.othersomething
select new { NewObject = c.othersomething };
DataTable MyDataTable = new DataTable();
myDataTable.Columns.Add(
new DataColumn()
{
DataType = System.Type.GetType("System.String"),//or other type
ColumnName = "Name" //or other column name
}
);
foreach (var element in query)
{
var row = MyDataTable.NewRow();
row["Name"] = element.NewObject;
myDataTable.Rows.Add(row);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…