C # add data queried by time period conditions in Access to ListView,

Source: Internet
Author: User

C # add data queried by time period conditions in Access to ListView,

C # add data queried by time period conditions in Access to ListView

 

1. How to display the table header in the ListView Control

Add a ListView space to the form. Set the attribute to "View" and add the text in the header in the Columns set.

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

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

ListViewItem listViewItem = new ListViewItem (); listViewItem. subItems [0]. text = "" 11111; // The value of listViewItem In the first example of the first line. subItems. add ("222"); // listViewItem. subItems. add ("222"); // and so on ListView1.Items. add (listViewItem );

Iii. SQL statement writing specification for time period query in Access (using the dateTimePick Control)
Note: # It must be added.

string sql=select * from tableName where timeField between #"+dateTimePick1.value.ToString()+"# and #"+dateTimePick2.vlaue.ToString()+"#";

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

string path = System.Environment.CurrentDirectory + "\\database.mdb";            OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path);//station2.mdb            con.Open();            string sql = "select * from SendRecord where SENDTIME between #" + dateTimePicker1.Value.ToString() + "# and #" + dateTimePicker2.Value.ToString() + "#";            // string sql = "select * from SendRecord";            OleDbDataAdapter da = new OleDbDataAdapter(sql, con);            DataSet dt = new DataSet();            da.Fill(dt);            DataTable dtb = dt.Tables[0];            foreach (DataRow row in dtb.Rows)            {                ListViewItem listviewItem = new ListViewItem();                listviewItem.SubItems.Clear();                listviewItem.SubItems[0].Text = string.Format("{0:yyyy-MM-dd HH:mm}", row["SENDTIME"]);                listviewItem.SubItems.Add((string)row["SENDER"]);                listviewItem.SubItems.Add((string)row["CONTENT"]);                listviewItem.SubItems.Add(string.Format("{0}", row["AUDITOR"]));                listviewItem.SubItems.Add(string.Format("{0:yyyy-MM-dd HH:mm}", row["AUDITTIME"]));                listviewItem.SubItems.Add(string.Format("{0}", row["AUDITSTATUS"]));                listView1.Items.Add(listviewItem);            }            con.Close();}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.