Transactions are fairly simple: You create a transaction before you make any changes, then you either Commit it when they all work, or Rollback if something fails:
private void DoDB(...)
{
string strConnect = SMDBSupport.SMInstanceStorage.GetInstanceConnectionString("Testing");
using (SqlConnection con = new SqlConnection(strConnect))
{
con.Open();
SqlTransaction transaction = con.BeginTransaction("MyTransaction");
try
{
using (SqlCommand cmd = new SqlCommand("...", con))
{
...
cmd.ExecuteNonQuery();
}
using (SqlCommand cmd = new SqlCommand("...", con))
{
...
cmd.ExecuteNonQuery();
}
transaction.Commit();
}
catch (Exception ex)
{
transaction.Rollback();
Console.WriteLine(ex.Message);
}
}
}