title: Unable to cast object of type 'System.Collections.Generic.List
body: <p>I am getting this error </p>
  
  <blockquote>
    <p>Unable to cast object of type
    'System.Collections.Generic.List`1[TransTripLeg]'
    to type 'System.Data.DataTable'.   </p>
  </blockquote>
  
  <p>and I can't seem to figure out how to resolve it. The error occurs at <code>DataTable dtTable =</code>  in the code below.   </p>
  
  <pre><code>if (!string.IsNullOrEmpty(Request.QueryString["EditMode"]))
  {
      DataTable dtUpdate = (DataTable)Session["TripRecords"];
      DataRow[] customerRow = dtUpdate.Select("LegID = '" + sLegID.ToString() + "'");
  </code></pre>
  
  <p>I think I am casting it to type DataTable, but then I still get the error.</p>