1
Reply

by using TrancationScope how can rollback autoincrement valu

khaleel shaik

khaleel shaik

Jan 28 2013 6:40 AM
1.4k
 

Hiany one can do this type of problems plz replay me ...

protected void Button1_Click(object sender, EventArgs e)

{

TransactionScope scope= new TransactionScope();

try

{

// Create the TransactionScope to execute the commands, guaranteeing

// that both commands can commit or roll back as a single unit of work.

using (scope )

{

EMPTEST();

EMPNAME();

// The Complete method commits the transaction. If an exception has been thrown,

// Complete is not called and the transaction is rolled back.

scope.Complete();

}

}

catch (TransactionAbortedException ex)

{

Debug.WriteLine("TransactionAbortedException Message: {0}", ex.Message);

}

catch (ApplicationException ex)

{

Debug.WriteLine("ApplicationException Message: {0}", ex.Message);

}

catch (IITBookKeeping.ExceptionBookKeeping ex)

{

Debug.WriteLine("ApplicationException Message: {0}", ex.Message);

}

finally

{

scope.Dispose();

}

Debug.WriteLine("Transaction Complete");

}

private void EMPNAME()

{

EMPNAMEBO name = new EMPNAMEBO();

name.CreateUser =

"Test";

name.CreateDateTime =

DateTime.Now;

name.dbName =

ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

name.id = 4;

name.name =

"Khaleel";

EMPNAMETO nameTx = new EMPNAMETO();

EMPNAMEBO name1 = new EMPNAMEBO();

name1 = nameTx.Add(name);

}

private void EMPTEST()

{

EMPTESTBO test = new EMPTESTBO();

test.CreateUser =

"Test";

test.CreateDateTime =

DateTime.Now;

test.dbName =

ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

test.Emp_name =

"khaleel";

test.Emp_Sal =

Convert.ToDecimal(10.2f);

EMPTESTBO test2 = new EMPTESTBO();

EMPTESTTO testTx = new EMPTESTTO();

test2 = testTx.Add(test);

}

v

Answers (1)