Mohamed Rafi

Mohamed Rafi

  • NA
  • 74
  • 9.1k

Confirmation before deleting the record

Mar 20 2022 3:00 PM

I am trying to confirm before delete, if i give ok means it asks confirmation corectly and records also deleting but if i give no means it didn't showing Good, We keep this record safe this messagebox, what is the error in code?

if (textBox6.Text!= "" && textBox7.Text != "" && textBox8.Text != "")
{
string connectionString;
MySqlConnection cnn;
connectionString = @"Data Source=localhost;Initial Catalog=testDB;User ID=root;Password=mysql";
cnn = new MySqlConnection(connectionString);
//string id = Convert.ToInt32(textBox6.Text);
string id = textBox6.Text;
string name = textBox7.Text;
string salary = textBox8.Text;
textBox6.Text = "";
textBox7.Text = "";
textBox8.Text = "";
string query = "DELETE FROM employee WHERE employee_id=@employee_id AND employee_name=@employee_name AND employee_salary=@employee_salary";
//string query = "select * from employee";
using (MySqlCommand cmd = new MySqlCommand(query))
{
cmd.Parameters.AddWithValue("@employee_id", id);
cmd.Parameters.AddWithValue("@employee_name", name);
cmd.Parameters.AddWithValue("@employee_salary", salary);
cmd.Connection = cnn;
cnn.Open();
cmd.ExecuteNonQuery();
DialogResult dr = MessageBox.Show("Are you sure to delete row?", "Confirmation", MessageBoxButtons.YesNo);
if (dr == DialogResult.Yes)
{
MessageBox.Show("Record Deleted Successfully");
cnn.Close();
DisplayData();
ClearData();
}
else if (DialogResult == DialogResult.No)
{
MessageBox.Show("Good, We keep this record safe");
}

}
}
else
{
MessageBox.Show("Please Select Record to Delete");
}
}


Answers (1)