Resolved Delete Query Error on code

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:
This question has nothing to do with C#. If you had provided us with the error message, as you should have, then we wouldn't have to guess but I suspect that you're being told that there is a syntax error in your DELETE statement. I suggest that you go back to your SQL reference and learn how to properly write a DELETE statement, because that's not it. That seems like you partly took it from an INSERT statement, which is structured differently.
 

Latest posts

Back
Top Bottom