i exacly copy from msdn but the following code gives me error
The type 'AnonymousType#1' cannot be used as type parameter 'T' in the generic type or method
'System.Data.DataTableExtensions.CopyToDataTable<T> (System.Collections.Generic.IEnumerable<T>,
System.Data.DataTable, System.Data.LoadOption)'. There is no implicit reference conversion from
'AnonymousType#1' to 'System.Data.DataRow'.
my code:
Item[] items = new Item[]
{
new Book{Id = 1, Price = 13.50, Genre = "Comedy", Author = "Gustavo Achong"},
new Book{Id = 2, Price = 8.50, Genre = "Drama", Author = "Jessie Zeng"},
new Movie{Id = 1, Price = 22.99, Genre = "Comedy", Director = "Marissa Barnes"},
new Movie{Id = 1, Price = 13.40, Genre = "Action", Director = "Emmanuel Fernandez"}
};
// Create a table with a schema that matches that of the query results.
DataTable dt1 = new DataTable();
dt1.Columns.Add("Price", typeof(int));
dt1.Columns.Add("Genre", typeof(string));
var query = from i in items
where i.Price > 9.99
orderby i.Price
select new { i.Price, i.Genre };
query.CopyToDataTable(dt1, LoadOption.PreserveChanges);
how to make it workabe?