title: How do I sort DataTable by ascending dates?
body: <p>My c# code downloads stock quotes into a DataTable object. The data comes as descending dates on the first column. I would like to sort this table as ascending dates. I've tried the following:</p>
  
  <pre><code>table.DefaultView.Sort = "Date";
  </code></pre>
  
  <p>sorts the table as if it were of string type, e.g.: "1/1/1994", "1/1/1995", "1/1/1996" instead of the desired "1/1/1994", "1/2/1994", "1/3/1994".</p>
  
  <p>Now, the following raises InvalidCastException.</p>
  
  <pre><code>var newTable = table.AsEnumerable().OrderBy(r =&gt; r.Field&lt;DateTime&gt;("Date")).CopyToDataTable();
  </code></pre>
  
  <p>Note: This sorting happens in a method that returns a DataTable object.</p>
  
  <p>[UPDATE]
  this is how I create and fill the table from a List where each entry is formatted as e.g.: "1/1/1994,21.01,22,21,21.01,23131,21.01"</p>
  
  <pre><code>        List&lt;string&gt; list = Downloaders.DownloadContentToList(symbol);
  
          DataTable table = new DataTable(symbol);
          table.Columns.Add("Date");
          table.Columns.Add("Open");
          table.Columns.Add("High");
          table.Columns.Add("Low");
          table.Columns.Add("Close");
          table.Columns.Add("Volume");
          table.Columns.Add("Adj Close");
  
              for (int i = 0; i &lt; list.Count; i++)
          {
              string[] cols = list[i].Split(',');
  
              DateTime date = Convert.ToDateTime(cols[0]);
              double open = Convert.ToDouble(cols[1]);
              double high = Convert.ToDouble(cols[2]);
              double low = Convert.ToDouble(cols[3]);
              double close = Convert.ToDouble(cols[4]);
              double volume = Convert.ToDouble(cols[5]);
              double adjClose = Convert.ToDouble(cols[6]);
              table.Rows.Add(date, open, high, low, close, volume, adjClose);
          }
  </code></pre>