C# filter datagridview between two dates from datetimepicker

Status
Not open for further replies.

dann11

Full Member level 3
Joined
Oct 22, 2015
Messages
166
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Activity points
2,742
Hi! i a trying to code a filter function to preview selected data by dates. dates will be chosen through datetimepicker and the filter doesnt work. I have my code below.


Code C# - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
void FilterDBbtnClick(object sender, EventArgs e)
        {   //filtering data for database display
                MySqlConnection conn = new MySqlConnection();
            
                conn = new MySqlConnection(cs);
                
                string data = "SELECT `Date`, `Process`, `Actual, `Target` FROM database WHERE `Date` `BETWEEN '"+this.fromDatePicker.Value.ToString()+"' AND  '"+this.toDatePicker.Value.ToString()+"' order by `Date` desc";
                        
                MySqlCommand cmd = new MySqlCommand(data, conn);
                
                cmd.Connection.Open();
                    
                try
                {
                    
                MySqlDataAdapter sda = new MySqlDataAdapter();
                sda.SelectCommand = cmd;            
                DataTable dt = new DataTable();
                sda.Fill(dt);
                BindingSource bsource = new BindingSource();
                bsource.DataSource = dt;
                mondeDataTable.DataSource = dt;
                sda.Update(dt);
                
                }
                
                catch (Exception)
                {
                    
                }
                
                cmd.Connection.Close();
        }

 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…