Skip to content

Instantly share code, notes, and snippets.

@luzemma
Last active May 9, 2019 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luzemma/8dff070a77588e94142c5d21c57f741d to your computer and use it in GitHub Desktop.
Save luzemma/8dff070a77588e94142c5d21c57f741d to your computer and use it in GitHub Desktop.
var query1 = "INSERT INTO tempoPerson (nombre, paterno) VALUES ('Jorge', 'Toribio');";
var query2 = "INSERT INTO tempoPerson (nombre, paterno) VALUES ('David', 'Lalane');";
var query3 = "INSERT INTO tempoPerson (nombre, paterno) VALUES ('Robert', 'Bloom');";
using (SqlConnection connection = new SqlConnection(strConn))
{
connection.Open();
SqlTransaction transaction = connection.BeginTransaction();
try
{
SqlCommand comm1 = new SqlCommand(query1, connection, transaction);
comm1.ExecuteNonQuery();
SqlCommand comm2 = new SqlCommand(query2, connection, transaction);
comm2.ExecuteNonQuery();
SqlCommand comm3 = new SqlCommand(query3, connection, transaction);
comm3.ExecuteNonQuery();
transaction.Commit();
}
catch (Exception ex)
{
transaction.Rollback();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment