I want to update ~50 rows. So i do it in a foreach The Code run without any errors but there are no changes in the database.
public void updateItems(List<product> prdList)
{
MySqlTransaction tr = null;
try
{
tr = this.con.BeginTransaction();
MySqlCommand cmd = new MySqlCommand();
cmd.Connection = con;
cmd.Transaction = tr;
foreach (product prd in prdList)
{
cmd.CommandText = "UPDATE products SET title='@title', quantity='@quantity' WHERE itemId LIKE '@itemId'";
cmd.Parameters.AddWithValue("@title", prd.title);
cmd.Parameters.AddWithValue("@quantity", prd.quantity);
cmd.Parameters.AddWithValue("@itemId", prd.itemId);
cmd.ExecuteNonQuery();
}
tr.Commit();
}
catch (MySqlException ex)
{
try
{
tr.Rollback();
}
catch (MySqlException ex1)
{
MessageBox.Show(ex1.ToString());
}
MessageBox.Show(ex.ToString());
}
}
If i print the Query String and run it on SQL-Bash, it works fine.