using System;

using System.Data;

using System.Data.SqlClient;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Transactions;

public partial class db_transaction_Default : System.Web.UI.Page

{

SqlConnection cn;SqlDataAdapter da;

SqlCommand cm;DataSet ds;

string sql, cnstr;protected void Page_Load(object sender, EventArgs e){

cnstr = “Data Source=(local);Initial Catalog=Northwind;Integrated Security=True”;cn =

new SqlConnection(cnstr);cn.Open();

Bind();

}

protected void Button1_Click(object sender, EventArgs e){

TransactionOptions options = new TransactionOptions();options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;options.Timeout =

new TimeSpan(0, 1, 0);try

{

using (TransactionScope Scope1 = new TransactionScope()){

string cnstr = “Data Source=(local);Initial Catalog=Northwind;Integrated Security=True”;SqlConnection cn1 = new SqlConnection(cnstr);cn1.Open();

if (cn1.State != ConnectionState.Open)cn1.Open();

sql = “insert into Table1 (c1, c2, c3) values (’22’,’22’,’22’)”;cm = new SqlCommand(sql, cn1);cm.ExecuteNonQuery();

sql = “insert into Table1 (c1, c2, c3) values (’33’,’22’,’22’)”;cm =

new SqlCommand(sql, cn1);cm.ExecuteNonQuery();

sql = “insert into Table1 (c1, c2, c3) values (’22’,’22’,’22’)”;cm = new SqlCommand(sql, cn1);cm.ExecuteNonQuery();

sql = “insert into Table1 (c1, c2, c3) values (’33’,’22’,’22’)”;cm =

new SqlCommand(sql, cn1);cm.ExecuteNonQuery();

Scope1.Complete();

}

}

catch (Exception ex){

throw ex;}

Bind();

}

public void Bind(){

if(cn.State!=ConnectionState.Open)cn.Open();

ds = new DataSet();sql = “Select * from Table1”;da =

new SqlDataAdapter(sql,cn);da.Fill(ds,“ds”);GridView1.DataSource = ds.Tables[

“ds”];GridView1.DataBind();

}

}