Hi
I have below code & i want if error comes then it should RollBack all transactions
foreach (var colum in Result)
{
DateTime? vSessionDate = null;
DateTime? vSessionStartTime = null;
DateTime? vSessionEndTime = null;
SessionDeliveryCalendar Rec = bALSessionDeliveryCalendar.GetRecordDetail(colum.SessionDeliveryCalendarID);
String vTime = Convert.ToDateTime(colum.SessionStartTime).ToString("HH") + ":" + Convert.ToDateTime(colum.SessionStartTime).ToString("mm");
String vDT1 = Convert.ToDateTime(Rec.SessionDate).AddDays(7 * Convert.ToInt32(ddlPush.SelectedValue)).ToString("dd-MM-yyyy") + " " + vTime;
DateTime StartDate = DateTime.ParseExact(vDT1, "dd-MM-yyyy HH:mm", System.Globalization.CultureInfo.InvariantCulture);
vSessionStartTime = Convert.ToDateTime(StartDate.ToString("yyyy-MM-dd HH:mm"));
int Res = bALSessionDeliveryCalendar.UpdateSessionDeliveryCalendar(Rec);
if (Res != 0)
{
vStatus = "T";
}
else
{
vStatus = "F";
ShowMessage("Error", "Record Update Failed, Please Try Again", "error");
BindData(Convert.ToInt32(hdfGroupID.Value), Convert.ToInt32(hdfModuleID.Value), true);
GetGroupInfo();
}
}
Thanks
Uday DodiyaPosted Apr 4, 2023, 6:39 AM
Use TransactionScope as per following
Anandu G NathPosted Dec 27, 2023, 8:42 AM
You can use
try-catchblocks in combination with theTransactionScopeclass in C# to manage transactions and rollback in case of an exception.Jignesh KumarPosted Apr 4, 2023, 6:41 AM
Hello Ramco,
Please refer this one which will help you, you need to use SQL transaction with try catch block,
if any error while execution then it will go to catch block. in catch block you can write rollback transaction
https://www.c-sharpcorner.com/uploadfile/john_charles/using-transactions-in-ado-net/
Manendra PaswanPosted Apr 4, 2023, 6:15 AM
Use TransactionScope