7
Answers

Updating SQL from C#, changing all the data

Benjamin Ashton

Benjamin Ashton

12y
2.5k
1
I am using the below code to try and update records within my SQL server but having problems, it is updating all the records to what I want it to change too. It would be great if someone could steer me in the right direction.

         da.UpdateCommand = new SqlCommand("UPDATE userInfo SET Username = @USERNAME, Password = @PASSWORD", cs);
            da.UpdateCommand.Parameters.Add("@USERNAME", SqlDbType.VarChar).Value = txtUsername.Text;
            da.UpdateCommand.Parameters.Add("@PASSWORD", SqlDbType.VarChar).Value = txtPassword.Text;

            cs.Open();
            da.UpdateCommand.ExecuteNonQuery();
            cs.Close();

            dgUpdate();

Answers (7)