Hi
In below code i am saving Data in Master table first & then Lines table. I want that Data should get saved simulataneouly in both tables.
If error is encountered at any stage then Data should RollBack in both tables
C#
protected void btnSubmit_Click(object sender, EventArgs e)
{
string Id = (sender as Button).ID;
try
{
BALTrainingHeader bALTrainingHeader = new BALTrainingHeader();
DateTime? dtFrom = null;
DateTime? dtTo = null;
if (hdfID.Value == "0")
{
if (txtdtFrom.Text.Trim() != "")
{
DateTime PMDate2 = DateTime.ParseExact(txtdtFrom.Text, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture);
dtFrom = Convert.ToDateTime(PMDate2.ToString("yyyy-MM-dd"));
}
if (txtdtTo.Text.Trim() != "")
{
DateTime PMDate2 = DateTime.ParseExact(txtdtTo.Text, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture);
dtTo = Convert.ToDateTime(PMDate2.ToString("yyyy-MM-dd"));
}
if (dtTo 0)
{
for (int i = 0; i < lstUsers.Items.Count; i++)
{
if (lstUsers.Items[i].Selected)
{
TrainingParticipant objLine = new TrainingParticipant();
objLine.TrainingID = Convert.ToInt32(hdfTrainingId.Value);
objLine.ParticipantID = Convert.ToInt32(lstUsers.Items[i].Value);
objLine.TrainingParticipantType = ddlWhom.SelectedItem.Value;
objLine.Deleted = false;
objLine.EntryDate = Utility.CurrentDateTime();
int objResult = bALTrainingHeader.AddRecordParticipant(objLine);
}
}
ShowMessageWithRedirect("", "Record Saved Successfully", "success", "DraftedTrainingList");
}
}
}
}
catch (Exception ex)
{
Utility.SaveErrorLog(ex.Message, System.IO.Path.GetFileName(Request.Path), System.Reflection.MethodBase.GetCurrentMethod().Name, hdfEmpNumber.Value);
ShowMessage("Oops...", ex.Message, "error");
}
}
Thanks

Amit MohantyRank #112 · 20K reputationPosted Sep 9, 2022, 6:33 AM EDT