c# - Linq results to dataTable with copyToDataTable -


i have linq results in dataset/datatable. problem have @ moment query variable doens't have propperty copytodatatable. error.

the type 'x.v_checklist' cannot used type parameter 't' in generic type or method 'system.data.datatableextensions.copytodatatable

this code

protected void btnexcelchecklistdownload_click(object sender, eventargs e) {     dataset dstest = new dataset();     var db = new billingentities();     var query = (from u in db.v_checklist select u).asqueryable();     datatable dt =  query.copytodatatable();     dstest.tables.add(dt);     excellibrary.datasethelper.createworkbook("myexcelfile.xls", dstest); } 

how can solve problem?

from how to: implement copytodatatable generic type t not datarow

the copytodatatable method takes results of query , copies data datatable, can used data binding. copytodatatable methods, however, operate on ienumerable source where generic parameter t of type datarow. although useful, not allow tables created sequence of scalar types, queries project anonymous types, or queries perform table joins.

it's why can't use directly copytodatatable without writing extensions.

the linked topic describes how implement 2 custom copytodatatable<t> extension methods accept generic parameter t of type other datarow.


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -