How to use Transaction in C# Code On Procedure?
>Solution :
You can do something like this using ADO .NET:
SqlConnection con = new SqlConnection("YOURConnection");
SqlCommand command = new SqlCommand("your procedure",con);
con.Open();
// this is a class you can use in order to manage transaction in C# for MS SQL
// start scope
SqlTransaction trans = con.BeginTransaction();
// set transaction for your command
command.Transaction = trans;
try
{
// execute your stored procedure or even multiple procedures/commands
command.ExecuteNonQuery();
// transaction will be successfully finished
trans.Commit();
}
catch (Exception)
{
// if any errors you need to rollback it
trans.Rollback();
}