how to create transaction concept in asp.net?

Posted by Prabu_Spark under ASP.NET on 6/3/2014 | Points: 10 | Views : 472 | Status : [Member] | Replies : 3
Hi sir,
Tell me, how to create transaction concept in asp.net. One interviewer asked this question, Kindly give me the solution for this problem.

With regards,
J.Prabu.
[Email:prbspark@gmail.com]



Responses

Posted by: kgovindarao523-21772 on: 6/3/2014 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,
Here is a sample example which i have tried earlier.

using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString))

{
con.Open();
SqlCommand objSqlCmd = new SqlCommand();
SqlTransaction objSqlTrans;
objSqlTrans = con.BeginTransaction();
objSqlCmd.Transaction = objSqlTrans;
try
{
objSqlCmd.Connection = con;
objSqlCmd.CommandType = CommandType.Text;//TEXT OR STORED PROCEDURE
objSqlCmd.CommandText = 'YOUR COMMAND OR SP';// DML commands
//Parameters if any
int result = objSqlCmd.ExecuteNonQuery();//YOUR Execution
if (result > 0)
{
objSqlTrans.Commit();
objSqlTrans.Dispose();
}
}
catch (SqlException)
{
objSqlTrans.Rollback();
}
}


Thank you,
Govind

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 6/4/2014 [Member] [MVP] Platinum | Points: 25

Up
0
Down
http://chandradev819.wordpress.com/2011/01/12/how-to-use-transaction-asp-net-project/

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Satyapriyanayak on: 6/6/2014 [Member] [MVP] Silver | Points: 25

Up
0
Down
http://www.c-sharpcorner.com/UploadFile/dchoksi/transaction02132007020042AM/transaction.aspx
http://www.codeproject.com/Articles/10223/Using-Transactions-in-ADO-NET

If this post helps you mark it as answer
Thanks

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response