Thanks Chaosian,
but I can't see how to call your code:
Dim Var051a As IEnumerable
Dim tableVar051 as DataTable
Var051a = From ...
tableVar051 = ?????(Var051a)
Main Topics
Browse All TopicsVB 2008
I want to convert a LINQ query to datatable.
I'm using this code:
Dim Var051a As IEnumerable
Dim tableVar051 as DataTable
Var051a = From ...
tableVar051 = ToDataTable(Var051a)
but it can't compile because says that can't determine the Var051a Type
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I use a similar approach, i think i took the inspiration from the same source as above. But instead of a generic function (it was very very slow), i define and use specific functions for each collection type. So for example i have a function called ShredClients to which i supply a collection of type Client (rather than T) and it specifically converts that type to a datatable. I have similar functions for the other few types i deal with.
The more complex the LINQ query is, the more likely it gets that you will not be able to pass an IEnumerable(Of T) or IQueryable(Of T) for that matter.
What you need then is a nifty little trick I read here: http://tomasp.net/articles
I haven't exactly figured out in your case how it needs to be implemented (can't expect me to do all your work). But if you look at this guy's "Cast" extension method it is able to determine the underlying type.
Perhaps I've steered you in the right direction with this?
Business Accounts
Answer for Membership
by: ChaosianPosted on 2009-09-21 at 11:59:57ID: 25386271
Well, we solved this problem in our production code base by stealing (oops, reusing) the code here: rad/archiv e/2007/09/ 07/science -project.a spx
http://blogs.msdn.com/acon
I've attached a VB version below... but there's a serious caveat emptor on it, since I just peeled out a bunch of project-specific classes.
Select allOpen in new window