In my program I want the user to have the option to change the value (price in my example) in a local database, that I created.
I'm having a problem with it. The connection works fine and it debugs well and even shows the message that "saving ok", but it doesn't change at all in the database.
private void button2_Click(object sender, EventArgs e)
{
var con = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\sam\Desktop\hello\hello\DB.mdf;Integrated Security=True";
using (SqlConnection myconnection = new SqlConnection(con))
{
try
{
myconnection.Open();
var query = string.Format("update DBTable set price='"+textBox2.Text+"' where ParamToCheck='"+comboBox5.Text+"'");
SqlCommand cm = new SqlCommand(query, myconnection);
cm.ExecuteNonQuery();
MessageBox.Show("saved ok !!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
The user can choose a string from the combobox5
and change his price from textBox2
by entering number - that what I want - but it doesn't change.