Hi all,
I've been developing a system for only 2 years. In other words, I'm still learning until now. One of the applications that I developed involves inserting header and details. My way of doing it is not the best one but I was able to do the task. However, there are times that the header fails to insert to DB but the details succeeded and vice versa. Below are my code snippet and I wish someone can share their ideas on how to make it in such a way that if the header fails, then the details value should not insert to DB and vice versa.
- try
- {
-
- header.SchoolYear = ddlSchoolYear.SelectedItem.Text;
- header.EnrollmentID = lblEnrollmentID.Text;
- header.StudentID = lblStudentID.Text;
- header.GradeLvl = ddlGradeLvl.SelectedItem.Text;
- header.EnrollmentFees = Convert.ToDouble(lblTotalFees.Text);
- header.Discount = Convert.ToDouble(txtDiscount.Text);
- header.PaymentTerms = Convert.ToInt32(ddlTermPayment.SelectedValue);
- header.SchoolCode = lblSchoolCode.Text;
- header.UserLogs = lblUsername.Text;
-
- insert.InsertEnrollmentHeader(header);
-
-
- #region ----charges
- foreach (GridViewRow row in gvCharges.Rows)
- {
- if (row.RowType == DataControlRowType.DataRow)
- {
- CheckBox Charges = (CheckBox)row.FindControl("cbCharges");
- if (Charges != null && Charges.Checked)
- {
- Label lblChargesID = (Label)row.FindControl("lblChargesID");
-
- charges.ChargesID = Convert.ToInt32(lblChargesID.Text);
- charges.EnrollmentID = lblEnrollmentID.Text;
-
- count = insert.InsertEnrollmentCharges(charges);
- }
- }
- }
Thanks in advance.