19GreenBlankets
19GreenBlankets

Reputation: 95

update not working correctly on button

Good day, My code below is not working. What it was supposed to do is to update all record with scee='WP' to 'RTP' when button is clicked. I'm really new to this. I'm sorry.

using (MySqlConnection resetcon1 = new MySqlConnection(connString))
{
    resetcon1.Open();
    string scee = "WP";

    MySqlCommand resetcom1 = 
        new MySqlCommand("UPDATE t_table SET scee=@scee WHERE scee ='RTP' ", resetcon1);

    resetcom1.Parameters.AddWithValue("scee", scee);
    resetcom1.ExecuteNonQuery();
    resetcon1.Close();
}

Thank you so much.

Upvotes: 0

Views: 30

Answers (1)

Magrones
Magrones

Reputation: 433

The way it is here you will change scee to "WP" where scee is equal to "RTP".

 "UPDATE t_table SET scee=@scee WHERE scee ='RTP' "

If you want to do the opposite as mentioned in your question it should be:

 "UPDATE t_table SET scee='RTP' WHERE scee =@scee "

You might need to add '' like this too:

 "UPDATE t_table SET scee='RTP' WHERE scee ='@scee' "

Upvotes: 1

Related Questions