Within the same transaction, you must have both database calls. That way, if you get an exception, everyone will be rollback.
It depends on how you access the database, but it could be something like this:
using (var Conn = new SqlConnection(_ConnectionString)) { SqlTransaction trans = null; try { Conn.Open(); trans = Conn.BeginTransaction(); using (SqlCommand Com = new SqlCommand(ComText, Conn, trans)) { // delete comment // update score } trans.Commit(); } catch (Exception Ex) { if (trans != null) trans.Rollback(); return -1; } }
source share