简体   繁体   中英

Filter Access filled dataGridView by datetimepicker value C#

Using my code below, I want to modify it so the dataGridView (dgReceived) is filtered by the "dateTimePicker1" (shown in the picture). It works great to retrieve data from the ACCESS database, but I need to add that filter functionality.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace dataGridView
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            OleDbConnection vcon = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;data source=C:\Query Form\Database.accdb");
            vcon.Open();
            DataSet ds = new DataSet();
            OleDbDataAdapter daReceived = new OleDbDataAdapter();

            OleDbCommand slctReceived = new OleDbCommand("SELECT * FROM script_Received", vcon);
            daReceived.SelectCommand = slctReceived;
            daReceived.Fill(ds, "tblReceived");

            dgReceived.DataSource = ds.Tables["tblReceived"];


        }

        private void dgReceived_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {

        }
    }
}

You can filter with a BindingSource which will sit between the table and the DGV's DataSource.

It has a Filter property that you use to filter data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM