Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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