I am trying to sort a DataTable
on a string
column by DateTime
.
For various reasons, the column must be left as a string
Try Add while create DataTable
table.Columns.Add("dateValue", typeof(DateTime?));
var orderedRows = from row in dt.AsEnumerable()
orderby row.Field("Date")
select row;
DataTable tblOrdered = orderedRows.CopyToDataTable();
(Or)
var orderedRows = from row in dt.AsEnumerable()
let date = DateTime.Parse(row.Field("Date"), CultureInfo.InvariantCulture)
orderby date
select row;