如何按日期降序排列显示的列表视图中访问数据库中的数据 [英] How to Display access database data in listview by date in descending order
本文介绍了如何按日期降序排列显示的列表视图中访问数据库中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用列表视图中显示访问数据库中的数据。
我是一个叫Date.there列有超过360天的数据每一个数据
例如日期,日期格式=年月日。
它显示上行
2011110420111105201111062011110720111108
我要降序显示这样的日期数据
2011110820111107201111062011110520111104
我使用这些code在列表视图中显示的数据存取权限。
尝试
{
con.Open();
DataTable的DT =新的DataTable();
DataSet的DS =新的DataSet();
ds.Tables.Add(DT);
OleDbDataAdapter的DA =新OleDbDataAdapter的(选择MyTable的*,CON);
da.Fill(DT);
INT iRecords = 0;
的foreach(在dt.Rows的DataRow myrow)
{
ListViewItem的诉讼=新的ListViewItem();
lItem.UseItemStyleForSubItems = FALSE;
诉讼= listviewTargets.Items.Insert(iRecords,与Date.toString());
//注意,在上述行与Date.toString写入
lItem.UseItemStyleForSubItems = FALSE;
// listviewTargets.Items.Add(myrow [2]的ToString());
lItem.SubItems.Add(myrow [0]的ToString());
lItem.SubItems.Add(myrow [3]的ToString());
lItem.SubItems.Add(myrow [14]的ToString());
lItem.SubItems.Add(myrow [4]的ToString(),Color.White,Color.Green,lItem.Font);
lItem.SubItems.Add(myrow [6]的ToString());
lItem.SubItems.Add(myrow [7]的ToString());
lItem.SubItems.Add(myrow [8]的ToString());
lItem.SubItems.Add(myrow [9]的ToString());
iRecords ++;
诉讼= listviewTargets.Items.Insert(iRecords,);
lItem.UseItemStyleForSubItems = FALSE; // iRecords = iRecords - 1;
// lItem.SubItems.Add();
lItem.SubItems.Add();
lItem.SubItems.Add();
lItem.SubItems.Add();
lItem.SubItems.Add(myrow [5]的ToString(),Color.White,Color.Red,lItem.Font);
lItem.SubItems.Add(myrow [10]的ToString());
lItem.SubItems.Add(myrow [11]的ToString());
lItem.SubItems.Add(myrow [12]的ToString());
lItem.SubItems.Add(myrow [13]的ToString());
iRecords ++;
}
// gv_ViewAllEntries.DataSource = ds.Tables [MyTable的];
con.Close();
}
赶上(例外)
{
con.Close();
}
在此先感谢
解决方案
OleDbDataAdapter的DA =新OleDbDataAdapter的(,CON由[日期]从递减的MyTable为了选择*);
I am using list view to display access database data.
I am a column called Date.there are more than 360 days data each with a data
Example Date , date format = yyyyMMdd.
it is displaying ascending
20111104
20111105
20111106
20111107
20111108
I want to Display the data by date in descending order like this
20111108
20111107
20111106
20111105
20111104
I am using these code to display acces data in list view.
try
{
con.Open();
DataTable dt = new DataTable();
DataSet ds = new DataSet();
ds.Tables.Add(dt);
OleDbDataAdapter da = new OleDbDataAdapter("select * from MyTable", con);
da.Fill(dt);
int iRecords = 0;
foreach (DataRow myrow in dt.Rows)
{
ListViewItem lItem = new ListViewItem();
lItem.UseItemStyleForSubItems = false;
lItem = listviewTargets.Items.Insert(iRecords, Date.ToString());
//Note in the above line "Date.ToString" is written
lItem.UseItemStyleForSubItems = false;
// listviewTargets.Items.Add(myrow[2].ToString());
lItem.SubItems.Add(myrow[0].ToString());
lItem.SubItems.Add(myrow[3].ToString());
lItem.SubItems.Add(myrow[14].ToString());
lItem.SubItems.Add(myrow[4].ToString(), Color.White, Color.Green, lItem.Font);
lItem.SubItems.Add(myrow[6].ToString());
lItem.SubItems.Add(myrow[7].ToString());
lItem.SubItems.Add(myrow[8].ToString());
lItem.SubItems.Add(myrow[9].ToString());
iRecords++;
lItem = listviewTargets.Items.Insert(iRecords, "");
lItem.UseItemStyleForSubItems = false;
//iRecords = iRecords - 1;
// lItem.SubItems.Add("");
lItem.SubItems.Add("");
lItem.SubItems.Add("");
lItem.SubItems.Add("");
lItem.SubItems.Add(myrow[5].ToString(), Color.White, Color.Red, lItem.Font);
lItem.SubItems.Add(myrow[10].ToString());
lItem.SubItems.Add(myrow[11].ToString());
lItem.SubItems.Add(myrow[12].ToString());
lItem.SubItems.Add(myrow[13].ToString());
iRecords++;
}
// gv_ViewAllEntries.DataSource = ds.Tables["MyTable"];
con.Close();
}
catch (Exception)
{
con.Close();
}
Thanks In Advance
解决方案
OleDbDataAdapter da = new OleDbDataAdapter("select * from MyTable order by [Date] desc", con);
这篇关于如何按日期降序排列显示的列表视图中访问数据库中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文