Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何按日期降序显示listview中的access数据库数据_C#_Winforms_Listview_Ms Access 2007 - Fatal编程技术网

C# 如何按日期降序显示listview中的access数据库数据

C# 如何按日期降序显示listview中的access数据库数据,c#,winforms,listview,ms-access-2007,C#,Winforms,Listview,Ms Access 2007,我正在使用列表视图显示access数据库数据 我是一个名为Date的列。有超过360天的数据,每个数据都有一个 示例日期,日期格式=yyyyMMdd。它正在向上显示 20111104 20111105 20111106 20111107 20111108 我想按日期按降序显示数据,如下所示 20111108 20111107 20111106 20111105 20111104 我正在使用这些代码在列表视图中显示acces数据 try { co

我正在使用列表视图显示access数据库数据

我是一个名为Date的列。有超过360天的数据,每个数据都有一个

示例日期,日期格式=yyyyMMdd。它正在向上显示

20111104

20111105

20111106

20111107

20111108
我想按日期按降序显示数据,如下所示

20111108

20111107

20111106

20111105

20111104
我正在使用这些代码在列表视图中显示acces数据

 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();
        }

提前感谢

请稍等一分钟,我会检查它是否正常工作我想使用OleDbDataAdapter da=新OleDbDataAdapter从realtimedata中选择*,其中Name='+Name+',con;因为还有很多名字,所以使用order。再次,请看一看并自己应用它。我的答案中已经有order BY子句。如果您想订购不同的查询,请自己应用该条款。我是ms access数据库的新手,您能帮我吗?如果您能帮助我,我们将不胜感激
OleDbDataAdapter da = new OleDbDataAdapter("select * from MyTable order by [Date] desc", con);