Explicit Transaction : SqlTransaction « ADO.Net « C# / CSharp Tutorial






using System;
using System.Data;
using System.Data.SqlClient;
using System.Transactions;
using System.Collections.Generic;
using System.Text;

    class Program
    {
        static void Main(string[] args)
        {
            CommittableTransaction tx = new CommittableTransaction();

            SqlConnection conn = new SqlConnection("data source=localhost; initial catalog=SampleDB; integrated security=SSPI;");
            conn.Open();

            SqlCommand updateCommand = conn.CreateCommand();
            updateCommand.CommandText = "DELETE Employees WHERE ID > 3";

            conn.EnlistTransaction(tx);

            updateCommand.ExecuteNonQuery();

            tx.Rollback();

            conn.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