Home Backend Development C#.Net Tutorial About how C# implements Access to add data queried by time period to ListView

About how C# implements Access to add data queried by time period to ListView

Jul 18, 2017 am 10:35 AM
.net access

这篇文章主要介绍了C# 将Access中以时间段条件查询的数据添加到ListView中,需要的朋友可以参考下

一、让ListView控件显示表头的方法

在窗体中添加ListView 空间,其属性中设置:View属性设置为:Detail,Columns集合中添加表头中的文字。

二、利用代码给ListView添加Item。

首先,ListView的Item属性包括Items和SubItems。必须先实例化一个ListIteView对象。具体如下:


ListViewItem  listViewItem=new ListViewItem();
listViewItem.SubItems[0].Text=""11111;//第一行第一例的值
listViewItem.SubItems.Add("222");///
listViewItem.SubItems.Add("222");///以此类推
ListView1.Items.Add(listViewItem);
Copy after login

三、Access中时间段查询的SQL语句书写规范(采用dateTimePick控件)

注意:# 是必须要加的


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

四、连接数据库,按条件查询数据并显示在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();
}
Copy after login

The above is the detailed content of About how C# implements Access to add data queried by time period to ListView. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Unable to log in to mysql as root Unable to log in to mysql as root Apr 08, 2025 pm 04:54 PM

The main reasons why you cannot log in to MySQL as root are permission problems, configuration file errors, password inconsistent, socket file problems, or firewall interception. The solution includes: check whether the bind-address parameter in the configuration file is configured correctly. Check whether the root user permissions have been modified or deleted and reset. Verify that the password is accurate, including case and special characters. Check socket file permission settings and paths. Check that the firewall blocks connections to the MySQL server.

How to use sql if statement How to use sql if statement Apr 09, 2025 pm 06:12 PM

SQL IF statements are used to conditionally execute SQL statements, with the syntax as: IF (condition) THEN {statement} ELSE {statement} END IF;. The condition can be any valid SQL expression, and if the condition is true, execute the THEN clause; if the condition is false, execute the ELSE clause. IF statements can be nested, allowing for more complex conditional checks.

How to use Debian Apache logs to improve website performance How to use Debian Apache logs to improve website performance Apr 12, 2025 pm 11:36 PM

This article will explain how to improve website performance by analyzing Apache logs under the Debian system. 1. Log Analysis Basics Apache log records the detailed information of all HTTP requests, including IP address, timestamp, request URL, HTTP method and response code. In Debian systems, these logs are usually located in the /var/log/apache2/access.log and /var/log/apache2/error.log directories. Understanding the log structure is the first step in effective analysis. 2. Log analysis tool You can use a variety of tools to analyze Apache logs: Command line tools: grep, awk, sed and other command line tools.

C# .NET: Exploring Core Concepts and Programming Fundamentals C# .NET: Exploring Core Concepts and Programming Fundamentals Apr 10, 2025 am 09:32 AM

C# is a modern, object-oriented programming language developed by Microsoft and as part of the .NET framework. 1.C# supports object-oriented programming (OOP), including encapsulation, inheritance and polymorphism. 2. Asynchronous programming in C# is implemented through async and await keywords to improve application responsiveness. 3. Use LINQ to process data collections concisely. 4. Common errors include null reference exceptions and index out-of-range exceptions. Debugging skills include using a debugger and exception handling. 5. Performance optimization includes using StringBuilder and avoiding unnecessary packing and unboxing.

Navicat connects to database error code and solution Navicat connects to database error code and solution Apr 08, 2025 pm 11:06 PM

Common errors and solutions when connecting to databases: Username or password (Error 1045) Firewall blocks connection (Error 2003) Connection timeout (Error 10060) Unable to use socket connection (Error 1042) SSL connection error (Error 10055) Too many connection attempts result in the host being blocked (Error 1129) Database does not exist (Error 1049) No permission to connect to database (Error 1000)

How to configure zend for apache How to configure zend for apache Apr 13, 2025 pm 12:57 PM

How to configure Zend in Apache? The steps to configure Zend Framework in an Apache Web Server are as follows: Install Zend Framework and extract it into the Web Server directory. Create a .htaccess file. Create the Zend application directory and add the index.php file. Configure the Zend application (application.ini). Restart the Apache Web server.

Solution to MySQL encounters 'Access denied for user' problem Solution to MySQL encounters 'Access denied for user' problem Apr 11, 2025 pm 05:36 PM

How to solve the MySQL "Access denied for user" error: 1. Check the user's permission to connect to the database; 2. Reset the password; 3. Allow remote connections; 4. Refresh permissions; 5. Check the database server configuration (bind-address, skip-grant-tables); 6. Check the firewall rules; 7. Restart the MySQL service. Tip: Make changes after backing up the database.

How to configure Debian Apache log format How to configure Debian Apache log format Apr 12, 2025 pm 11:30 PM

This article describes how to customize Apache's log format on Debian systems. The following steps will guide you through the configuration process: Step 1: Access the Apache configuration file The main Apache configuration file of the Debian system is usually located in /etc/apache2/apache2.conf or /etc/apache2/httpd.conf. Open the configuration file with root permissions using the following command: sudonano/etc/apache2/apache2.conf or sudonano/etc/apache2/httpd.conf Step 2: Define custom log formats to find or

See all articles