Created
May 6, 2015 20:55
-
-
Save ashtewari/b0da28ad3efd787a7e61 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void ExecuteSqlTransactionUsingTransactionScope(string connectionString) | |
{ | |
using(TransactionScope scope = new TransactionScope()) | |
{ | |
using (SqlConnection connection = new SqlConnection(connectionString)) | |
{ | |
connection.Open(); | |
SqlCommand command = connection.CreateCommand(); | |
command.Connection = connection; | |
command.CommandText = "Insert into MyTable(ColumnA, ColumnB) VALUES (1234, 'ValueB')"; | |
command.ExecuteNonQuery(); | |
command.CommandText = "Insert into MyTable(ColumnA, ColumnB) VALUES (5678, 'Another Value')"; | |
command.ExecuteNonQuery(); | |
Console.WriteLine("Both records are written to database."); | |
} | |
scope.Complete(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment