---
title: "Filling a DataSet or DataTable from a LINQ query result set"  
description: "Filling a DataSet or DataTable from a LINQ query result set"  
author: "Anonymous User"  
published: 2013-12-27  
updated: 2013-12-27  
canonical: https://www.mindstick.com/forum/1841/filling-a-dataset-or-datatable-from-a-linq-query-result-set  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Filling a DataSet or DataTable from a LINQ query result set

How do you expose a [LINQ query](https://www.mindstick.com/forum/33908/how-to-select-and-retrieve-data-using-linq-query-in-entity-framework) as an ASMX [web service](https://www.mindstick.com/articles/895/web-service-introduction)? Usually, from the [business](https://www.mindstick.com/articles/12213/how-to-start-a-jewellery-making-business-online-business-ideas) tier, I can return a [typed](https://www.mindstick.com/interview/33645/what-is-the-difference-between-typed-and-untyped-dataset) [DataSet](https://www.mindstick.com/articles/19/dataset) or [DataTable](https://www.mindstick.com/blog/195/datatable-in-ado-dot-net) which can be serialized for [transport](https://answers.mindstick.com/qa/72238/india-s-first-rail-transport-university-will-be-established-at-which-city) over ASMX.

How can I do the same for a LINQ query? Is there a way to [populate](https://www.mindstick.com/blog/60/populate-records-in-second-listbox-according-to-the-selection-in-first-list-box) a typed DataSet or DataTable via a LINQ query?:

```
public static MyDataTable CallMySproc()    {        string conn = ...;   
MyDatabaseDataContext db = new MyDatabaseDataContext(conn);        MyDataTable dt =new MyDataTable();    // execute a sproc via LINQ    var query = from dr in db.MySproc().AsEnumerable    select dr;    // copy LINQ query resultset into a DataTable -this does not work !        dt = query.CopyToDataTable();    return dt;}
```

How can I get the resultset of a LINQ query into a DataSet or DataTable? Alternatively, is the LINQ query serializeable so that I can expose it as an ASMX web service?

## Replies

### Reply by Anonymous User

Hi Ankit,

As mentioned in the question, IEnumerable has a CopyToDataTable method:

```
IEnumerable<DataRow> query =    from order in orders.AsEnumerable()    where
order.Field<DateTime>("OrderDate") > new DateTime(2001, 8,
1)    select order;// Create a table from the query.DataTable boundTable = query.CopyToDataTable<DataRow>();
```


---

Original Source: https://www.mindstick.com/forum/1841/filling-a-dataset-or-datatable-from-a-linq-query-result-set

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
