Mohamed Rafi

Mohamed Rafi

  • NA
  • 74
  • 9k

delete query error

Mar 20 2022 3:37 AM

Mysql Delete record query error, if i select record from gridview that record shouls deleted from mysql database

private void button9_Click(object sender, EventArgs e)
{
if (ID != 0)
//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 = textBox6.Text;
string name = textBox7.Text;
string salary = textBox8.Text;
textBox6.Text = "";
textBox7.Text = "";
textBox8.Text = "";
string query = "delete employee where(@employee_id, @employee_name, @employee_salary)";
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();
MessageBox.Show("Record Deleted Successfully");
cnn.Close();
DisplayData();
ClearData();
}
}
else
{
MessageBox.Show("Please Select Record to Delete");
}
}
}


Answers (4)