SoFunction
Updated on 2025-03-07

How to add data queried in Access with time period conditions to ListView

1. How to let the ListView control display the header

Add ListView space to the form, and set the:View property to: Detail, add text in the table header in the Columns collection.

2. Use the code to add an Item to the ListView.

First, the Item properties of ListView include Items and SubItems. A ListIteView object must be instantiated first. The details are as follows:

ListViewItem  listViewItem=new ListViewItem();
[0].Text=""11111;//The value of the first line, first example("222");///
("222");/// and so on(listViewItem);

3. SQL statement writing specifications for time period query in Access (using dateTimePick control)

Note: # is a must

string sql=select * from tableName where timeField between #"+()+"# and #"+()+"#";

4. Connect to the database, query the data according to conditions and display it in ListView

string path =  + "\\";
      OleDbConnection con = new OleDbConnection("Provider=.12.0;Data Source=" + path);//
      ();
      string sql = "select * from SendRecord where SENDTIME between #" + () + "# and #" + () + "#";
      // string sql = "select * from SendRecord";
      OleDbDataAdapter da = new OleDbDataAdapter(sql, con);
      DataSet dt = new DataSet();
      (dt);
      DataTable dtb = [0];
      foreach (DataRow row in )
      {
        ListViewItem listviewItem = new ListViewItem();
        ();
        [0].Text = ("{0:yyyy-MM-dd HH:mm}", row["SENDTIME"]);
        ((string)row["SENDER"]);
        ((string)row["CONTENT"]);
        (("{0}", row["AUDITOR"]));
        (("{0:yyyy-MM-dd HH:mm}", row["AUDITTIME"]));
        (("{0}", row["AUDITSTATUS"]));
        (listviewItem);
      }
      ();
}