private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { connection.Open(); string selectQuery = "SELECT * FROM floral_shop_db.ex5 WHERE productName = '" + comboBox1.Text + "' "; MySqlCommand command = new MySqlCommand(selectQuery, connection); MySqlDataReader MDR; try { MDR = command.ExecuteReader(); if (MDR.Read()) { textBox3.Text = MDR.GetString("proPrice"); } else { textBox3.Text = ""; comboBox1.Text = ""; } } catch (Exception ex) { MessageBox.Show(ex.Message); } connection.Close(); }
private void button3_Click(object sender, EventArgs e) { if (textBox3.Text == "")//validating the name textbox { textBox3.BackColor = Color.LightPink; MessageBox.Show("Name is Required", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Information); textBox3.Focus(); return; } connection.Open(); string selectQuery = "SELECT * FROM floral_shop_db.ex1 WHERE name = '" + textBox3.Text + "' "; MySqlCommand command = new MySqlCommand(selectQuery, connection); MySqlDataReader MDR; try { MDR = command.ExecuteReader(); if (MDR.Read()) { textBox2.Text = MDR.GetString("email"); textBox1.Text = MDR.GetString("addr"); } else { textBox3.Text = ""; textBox2.Text = ""; textBox1.Text = ""; MessageBox.Show("you are not logged in"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } connection.Close(); }