How can i Add or substract on data already existing in mysql Db.(c#)
try
{
conn = new MySqlConnection(cs.ConnString);
conn.Open();
cmd = new MySqlCommand();
cmd.Connection = conn;
cmd.CommandText= "update Compte set Solde_Actuel_$ = Solde_Actuel_$ - " + MontantDollars_AAS_txt.Text + " WHERE Code_Compte='" + Code_txt.Text + "'";
cmd.ExecuteReader();
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
I use MSSQL server and your code works for me. The data were successfully updated. I think there may be a problem with runtime value of your .Text variable
try
{
var propertyText = "Test2";
var conn = new SqlConnection(_configuration.GetConnectionString("Default"));
conn.Open();
var cmd = new SqlCommand
{
Connection = conn,
CommandText = "update Terminals set Zipcode = " + 123 + " WHERE Name='" + propertyText + "'"
};
cmd.ExecuteReader();
conn.Close();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.