title: System.Data.DataRowCollection' does not contain a definition for 'Cast'
body: <p>I am stuck here , the following method shows error  </p>
  
  <blockquote>
    <p>'System.Data.DataRowCollection' does not contain a definition for
    'Cast' and the best extension method overload
    'System.Data.EnumerableRowCollectionExtensions.Cast(System.Data.EnumerableRowCollection)'
    has some invalid arguments</p>
  </blockquote>
  
  <p>How to resolve this I tried datatable.AsEnumerable but wont work. The bold lines in the code shows this error.
  Help me please.</p>
  
  <p>Here is the code</p>
  
  <pre><code>   public void DataExport(string SelectQuery)// server code
     {
         try
         {
             using (var dt = new DataTable())
             {
                 using (var da = new SqlDataAdapter(SelectQuery, con))
                 {
                     da.Fill(dt);
                     var rows =
                         **from dr in dt.Rows.Cast&lt;DataRow&gt;()**
                         select String.Join(
                             ",",
                             **from dc in dt.Columns.Cast&lt;DataColumn&gt;()**
                             let t1 = Convert.IsDBNull(dr[dc]) ? "" : dr[dc].ToString()
                             let t2 = t1.Contains(",") ? String.Format("\"{0}\"", t1) : t1
                             select t2);
  
  
  
                     using (var sw = new StreamWriter("somepath"))
                     {
                         // sw.WriteLine(header);
                         foreach (var row in rows)
                         {
                             sw.WriteLine(row);
                         }
                         sw.Close();
                     }
                 }
             }
         }
         catch (Exception e) { Console.WriteLine(e.Message); }
     }
  </code></pre>