在c#的Access中按日期排序数据
本文关键字:日期 排序 数据 Access | 更新日期: 2023-09-27 17:50:34
我想根据升序的日期获取数据。代码正在获取数据,但格式错误,例如:
14/02/2014
16/01/2014
17/04/2013
。日期是基于"dd"排序的,只考虑月份和年份代码在
下面string constr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|'Auto_Finance.accdb;Persist Security Info=False;";
OleDbConnection con = new OleDbConnection(constr);
con.Open();
string sql=@"select p.PName,p.hpno,c.Credit,C.Debit,c.Dates from Party_Det p inner join cd c on p.Loanno=c.Loanno order by c.Dates asc";
OleDbCommand cmd = new OleDbCommand(sql, con);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
con.Close();
但是我想要下面的结果
17/04/2013
16/01/2014
14/02/2014
我使用c#作为前端,Microsoft Access作为前端。
您的查询是
@"select p.PName,p.hpno,c.Credit,C.Debit,c.Dates from Party_Det p inner join cd c on p.Loanno=c.Loanno order by c.Dates desc"
如Gordon所说
将" c.Dates desc
"替换为" c.Dates ASC
"
试试这个:
string sql = @"select p.PName,p.hpno,c.Credit,C.Debit,c.Dates from Party_Det p inner join cd c on p.Loanno=c.Loanno order by c.Dates desc";
或:
string sql = @"select p.PName,p.hpno,c.Credit,C.Debit,c.Dates from Party_Det p inner join cd c on p.Loanno=c.Loanno";
...
dataGridView1.DataSource = dt;
dataGridView1.Sort('Dates', SortDirection.Descending);