Updating Data Using Transactions : SqlTransaction « ADO.Net « C# / CSharp Tutorial






using System;
using System.Data;
using System.Data.SqlClient;


class MainClass
{
  static void Main(string[] args)
  {
    SqlConnection MyConnection = new SqlConnection("server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI;");

    MyConnection.Open();

    String MyString = "INSERT INTO Employee(ID, FirstName)VALUES(1, 'Greg')";
    SqlTransaction MyTransaction = MyConnection.BeginTransaction();
    SqlCommand MyCmd = new SqlCommand(MyString, MyConnection, MyTransaction);

    MyCmd.ExecuteScalar();
    MyTransaction.Commit();
    MyConnection.Close();
  }
}








32.28.SqlTransaction
32.28.1.Updating Data Using Transactions
32.28.2.the use of a transaction
32.28.3.Nested Implicit Transaction
32.28.4.Implicit Transaction
32.28.5.Explicit Transaction