How to sort dataset on basic of Date.
Thanks in advance...
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
KalaiPosted Mar 12, 2014, 7:28 AM
public DataTable sortDate()
{
DataTable dt = new DataTable();
dt.Columns.Add("Id", typeof(int));
dt.Columns.Add("Date", typeof(DateTime));
dt.Rows.Add(1, System.DateTime.Now);
dt.Rows.Add(2, System.DateTime.Now.AddDays(1));
dt.Rows.Add(3, System.DateTime.Now.AddDays(2));
DataSet ds = new DataSet();
ds.Tables.Add(dt);
ds.Tables[0].DefaultView.Sort = "Date desc";
DataTable dtSort = ds.Tables[0].DefaultView.ToTable();
return dtSort;
}
VulpesPosted Mar 12, 2014, 7:15 AM
DataTable dt = ds.Tables[0];