title: Querying a DataTable using LINQ
body: <p>First apologies if I don't explain this properly, I've been at this for hours, and it's now morning. </p>
  
  <p>I've tried so many methods, got so many errors that I can't remember the original version, nor can I solve the problem, here's my code, it's terrible as I should be using a join query my SP's are bugged on this server.</p>
  
  <pre><code>SqlConnection conn = new SqlConnection(connstring);
  DataSet ds = new DataSet();
  SqlDataAdapter ad;
  SqlCommand cmd = new SqlCommand();
  ad = new SqlDataAdapter("SELECT * FROM booking WHERE bookstartdate BETWEEN '" + ReturnDbDate(datefrom).ToString() + "' AND '" + ReturnDbDate(dateto).ToString() + "'", conn);
  ad.Fill(ds, "CustomerIds");
  
  ad = new SqlDataAdapter("SELECT customerid, firstname, lastname, telephone, email FROM customer", conn);
  ad.Fill(ds, "Customers");
  
  DataTable dt = new DataTable();
  dt.Columns.Add("Customerid", typeof(String));
  dt.Columns.Add("Firstname", typeof(String));
  dt.Columns.Add("Lastname", typeof(String));
  dt.Columns.Add("Telephone", typeof(String));
  dt.Columns.Add("Email", typeof(String));
  
  int lol = ds.Tables["CustomerIds"].Rows.Count;
  
  foreach (DataRow row in ds.Tables["CustomerIds"].Rows)
  {
      IEnumerable&lt;DataRow&gt; r = from dr in ds.Tables["Customers"].AsEnumerable()
                               where dr.Field&lt;Guid&gt;("customerid").ToString() == row[2].ToString()
                               select dr;
      dt.Rows.Add(r);
  }
  
  return dt;
  </code></pre>
  
  <p>When I try loop through the dataset using the following:</p>
  
  <pre><code>foreach (DataRow rows in dt.Rows)
  {
      sb.Append("&lt;tr&gt;&lt;td&gt;" + rows["Customerid"].ToString() + "&lt;/td&gt;&lt;td&gt;" + rows[1] + "&lt;/td&gt;&lt;td&gt;" + rows[2] +"&lt;/td&gt;&lt;td&gt;" + rows[3] + "&lt;/td&gt;&lt;/tr&gt;");
  }
  </code></pre>
  
  <p>I get:</p>
  
  <blockquote>
    <p>System.Data.EnumerableRowCollection`1[System.Data.DataRow]</p>
  </blockquote>
  
  <p>Anyone any ideas? Completely brain dead atm so it might be something simple.</p>
  
  <p>Thanks</p>
  
  <p>Edit:</p>
  
  <pre><code>DataRow r = from dr in ds.Tables["Customers"]
              where dr.Field&lt;Guid&gt;("customerid").ToString() == row[2].ToString()
              select dr;    
  dt.ImportRow(r);
  </code></pre>
  
  <blockquote>
    <p>Error: Could not find an implementation of the query pattern for source type 'System.Data.DataTable'.  'Where' not found.</p>
  </blockquote>
  
  <p>I'm assuming my LINQ syntax is not incorrect, although I think there's a <code>IEnumberable&lt;T&gt;.Where()</code> method? I remember it, just can't remember how to access it.</p>
  
  <p>Edit2:</p>
  
  <p>I fail, managed to re-create the problem again, sigh</p>
  
  <pre><code> IEnumerable&lt;DataRow&gt; r = from dr in ds.Tables["Customers"].Select().Where(x =&gt; x.Field&lt;Guid&gt;("customerid").ToString() == row[2].ToString())
                              select dr;
  
  
  
                  dt.ImportRow(r);
  </code></pre>