Abe Miessler
Abe Miessler

Reputation: 85046

How to convert Linq query to a DataTable, DataSet or DataView?

Is there an easy way to do this or do I just need to go through each record and insert it into whatever data structure I go with?

I need it in this format in order to pass it to a third party software called Aspose.

Upvotes: 0

Views: 2192

Answers (2)

hemme
hemme

Reputation: 1652

DataSets are about DataTables; DataTables and DataViews are about DataRows. Linq queries are about objects.

If you want to execute a Linq2SQL query or Linq2Entities query and put the result into a collection of DataRows you will have to manually convert each instance of your query result to a DataRow type (and define the various DataColumns...).

The trivial solution of you question is using a LINQ query towards a DataTable... it will return a set of DataRows... but I don't think this is the main point of you question.

Upvotes: 1

Randy Minder
Randy Minder

Reputation: 48402

You should be able to set the DataSource property to the results of any Linq query.

Upvotes: 0

Related Questions