I want update several columns in a table by adding a value to existing values in those columns. Here is my current code:
cmd = new SqlCommand("UPDATE Users SET Debit=@debit,
Score=@score
WHERE Phone=@phone", con);
con.Open();
cmd.Parameters.AddWithValue("@phone", textBox1.Text);
cmd.Parameters.AddWithValue("@debit", textBox2.Text);
cmd.Parameters.AddWithValue("@score", textBox3.Text);
cmd.ExecuteNonQuery();
MessageBox.Show("Амжилттай");
con.Close();
For example:
Table, Phone: 999 | Debit: 1500 | Score: 100 //current
When I add value from textBox1 = 999, textBox2 = 500, textBox3 = 50, the values should become:
Table, Phone: 999, Debit: 2000, Score: 150 //updating like that
I know how to do this via a SQL query, but I don't know how to write the code in a SqlCommand in .NET:
UPDATE Users
SET Debit = Debit + [user input], Score = Score + [user input]
WHERE = Phone
Any suggestions?