How to sort dataset on basic of Date.
Thanks in advance...
How to sort dataset on basic of Date.
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Mar 12, 2014, 3:15 AM EDT
DataTable dt = ds.Tables[0];
KalaiRank #8,005 · 230 reputationPosted Mar 12, 2014, 3:28 AM EDT
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;
}