private void button1_Click(object sender, EventArgs e) { string constring = "datasource=localhost;port=3306;username=root;password=Ammoos123"; MySqlConnection conDatabase = new MySqlConnection(constring); if((this.cmb2.SelectedItem.ToString())=="SafetyInspection_Report") { MySqlCommand cmdDatabase = new MySqlCommand("select * from vehicle_automation.safetyinspection_report where vehRegNo=@regno and inspection_date between @date1 and @date2", conDatabase); cmdDatabase.Parameters.AddWithValue("@regno", this.cmb1.SelectedItem); cmdDatabase.Parameters.AddWithValue("@date1", this.dt1.Text); cmdDatabase.Parameters.AddWithValue("@date2", this.dt2.Text); try { MySqlDataAdapter sda = new MySqlDataAdapter(); sda.SelectCommand = cmdDatabase; DataTable dbdataset = new DataTable(); sda.Fill(dbdataset); BindingSource bsource = new BindingSource(); bsource.DataSource = dbdataset; dtgv1.DataSource = bsource; sda.Update(dbdataset); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else if((this.cmb2.SelectedItem.ToString())=="Maintenance_log") { MySqlCommand cmdDatabase = new MySqlCommand("select * from vehicle_automation.maintenance_log where vehRegNo=@regno and inspection_date between @date1 and @date2", conDatabase); cmdDatabase.Parameters.AddWithValue("@regno", this.cmb1.SelectedItem); cmdDatabase.Parameters.AddWithValue("@date1", this.dt1.Text); cmdDatabase.Parameters.AddWithValue("@date2", this.dt2.Text); try { MySqlDataAdapter sda = new MySqlDataAdapter(); sda.SelectCommand = cmdDatabase; DataTable dbdataset = new DataTable(); sda.Fill(dbdataset); BindingSource bsource = new BindingSource(); bsource.DataSource = dbdataset; dtgv1.DataSource = bsource; sda.Update(dbdataset); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
Quote:Hi How can i show a message if there is no data on the database for the search criteria?
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)