What would be the easiest way to fill datatable with dblinq?

13 views
Skip to first unread message

hiren

unread,
Mar 6, 2011, 1:43:44 PM3/6/11
to DbLinq
Hi,

I have generated a cs file from my database using the tool DbMetal.
I am executing the following query:
MyDb db = new MyDb(new MySqlConnection("Database=MyDbase;Data
Source=localhost;User Id=root;Password=");
var query = from customer in db.TblCustomers select customer;
DataTable dtable = query.CopyToDataTable();


Some how i am unable to execute the above mentioned line.
i understand that for CopyToDataTable to execute the result type
should be of IEnumerable<DataRow>, how can i possibly get the output
of the linq query to be of type IEnumerable<DataRow>. Is this because
the TblCustomers in my cs file generated by DbMetal is having some
limitation??
I am new to DbLinq, any light drawn here will be greatly appreciated.


I had one more doubt, don't know if the latter follows the former.
I read a lot of posts on LINQ to Datatable/dataset , some of which
would ask to execute the following query :

var query = db.TblCustomers.AsEnumerable().Select(customer =>
customer.Field<String>("CustName"));
But it throws an error :
The type arguments for method
'System.Data.DataTableExtensions.CopyToDataTable<T>(System.Collections.Generic.IEnumerable<T>)'
cannot be inferred from the usage. Try specifying the type arguments
explicitly.

Thanks & Regards
hiren
Reply all
Reply to author
Forward
0 new messages