maddyrafi
New member
- Joined
- Mar 19, 2022
- Messages
- 4
- Programming Experience
- Beginner
Mysql Delete record query error, if i select record from gridview that record shouls deleted from mysql database
C#:
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");
}
}
Last edited by a moderator: