about how C # implements access to data from time-period queries added to the ListView

Source: Internet
Author: User
This article focuses on C # to add data from access to a time period condition query in the ListView, and the friends you need can refer to the following

First, let the ListView control display the table header method

In the form, add the ListView space to its properties in the settings: The View property is set to: Detail,columns the text in the header of the collection.

Second, use the code to add item to the ListView.

First, the Item property of the ListView includes items and subitems. You must instantiate a Listiteview object first. Specific as follows:


ListViewItem  listviewitem=new ListViewItem (); Listviewitem.subitems[0]. Text= "" 11111;//the value of the first example of the first line LISTVIEWITEM.SUBITEMS.ADD ("222");///listviewitem.subitems.add ("222");/// etc. ListView1.Items.Add (ListViewItem);

III. SQL Statement Writing specification for time period queries in Access (with Datetimepick control)

Note: # must be added.


String Sql=select * from TableName where Timefield between # "+datetimepick1.value.tostring () +" # and # "+ DateTimePick2.vlaue.ToString () + "#";

Iv. connecting to the database, querying data conditionally and displaying it in the 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 #" + DateTime      Picker2.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 ();}

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.