Hi
any 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
Jignesh TrivediPosted Jan 28, 2013, 11:02 PM
This is the behaviour of IDENTITY columns and i think it cannot be changed. The reason is that you could have multiple users inserting new rows at same time, and SQL Server would have to keep track of which identity values were actually used if any transactions were rolled back.
You either need to accept this behavior and write your code based on it, or manage the new values in that column yourself.
hope this will help you.