title: Convert a LINQ Query Resultset to a DataTable
body: <p>How can i write this query with LINQ to a FoxPro database?</p>
  
  <pre><code>SELECT count(*) FROM Table group by item1
  </code></pre>
  
  <p>I wrote it as below, but it doesn't work</p>
  
  <pre><code>Dim Query
  
  Dim dt As New DataTable
  
  Dim da = New Odbc.OdbcDataAdapter("SELECT * FROM  table1",connection)
  da.Fill(dt)
  
  Query = (From row In dt.AsEnumerable Select row_
            Group By item1 = row.Item(6) Into_       
           count = Count(row.Item(6))).ToList
  </code></pre>
  
  <p>The following line works:</p>
  
  <pre><code>    Dim q = From p In dt Group p By item = p.Item(6) Into count = Count()
  </code></pre>
  
  <p>How can I bind the results of the above query to a GridView? Unfortunately, setting <code>q</code> as DataSource doesn't work</p>
  
  <pre><code>    grid.DataSource= q
  </code></pre>
  
  <p>I found that i shoud bind it this way</p>
  
  <pre><code>    Dim table As DataTable = q.ToDataTable()
      DataGridView1.DataSource = table
  </code></pre>
  
  <p>but i et error like this</p>
  
  <pre><code>    'copytodatatable' is not a member of 'System.Collections.Generic.IEnumerable
  </code></pre>
  
  <p>what is this error refers to?</p>