dann11
Full Member level 3
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(); }