Tags: bindingnavigator, bindingsource, bindingsources, child, detail, form, forms, multiple, net, objects, parent, saving, tab-control, updating, web

Updating/Saving Child Data Using BindingSource and BindingNavigator

On .Net » Web Forms

6,434 words with 2 Comments; publish: Tue, 01 Jan 2008 03:10:00 GMT; (100140.63, « »)

I have a form with multiple bindingSource objects. The parent bindingSource is on the form and the child/detail bindingSources are on a tab-control.

I can save the parent data but not the child. I am very frustrated, does anyone know how to go about this? I will lose my sanity soon. Below is my save code:

private void estimate_procedureBindingNavigatorSaveItem_Click(object sender, EventArgs e)

{

try

{

this.Validate();

this.estimate_procedureBindingSource.EndEdit();

this.estimatesBindingSource.EndEdit();

this.cabinetBindingSource.EndEdit();

this.cylinderBindingSource.EndEdit();

this.pipeBindingSource.EndEdit();

this.angleIronBindingSource.EndEdit();

this.barsBindingSource.EndEdit();

this.railBindingSource.EndEdit();

this.beams_channelsBindingSource.EndEdit();

this.givenBindingSource.EndEdit();

this.circumferenceBindingSource.EndEdit();

this.diameterBindingSource.EndEdit();

DataTable est_procTable = this.usmDataSetProcA.estimate_procedure;

DataTable estTable = this.usmDataSetProcA.estimates;

DataTable cabTable = this.usmDataSetProcA.cabinet;

DataTable cylTable = this.usmDataSetProcA.cylinder;

DataTable pipeTable = this.usmDataSetProcA.pipe;

DataTable angleTable = this.usmDataSetProcA.angle_irons;

DataTable barsTable = this.usmDataSetProcA.bars;

DataTable railTable = this.usmDataSetProcA.rail;

DataTable beamChannelTable = this.usmDataSetProcA.beams_channels;

DataTable givenTable = this.usmDataSetProcA.given;

DataTable circumTable = this.usmDataSetProcA.circumference;

DataTable diameterTable = this.usmDataSetProcA.diameter;

DataRow[] rows;

rows = est_procTable.Select("", "", DataViewRowState.Added | DataViewRowState.ModifiedCurrent|DataViewRowState.ModifiedOriginal);

this.estimate_procedureTableAdapter.Update(rows);

rows = estTable.Select("", "", DataViewRowState.Added | DataViewRowState.ModifiedCurrent | DataViewRowState.ModifiedOriginal);

this.estimatesTableAdapter.Update(rows);

rows = cabTable.Select("", "", DataViewRowState.Added | DataViewRowState.ModifiedCurrent | DataViewRowState.ModifiedOriginal);

this.cabinetTableAdapter.Update(rows);

rows = cylTable.Select("", "", DataViewRowState.Added | DataViewRowState.ModifiedCurrent | DataViewRowState.ModifiedOriginal);

this.cylinderTableAdapter.Update(rows);

rows = pipeTable.Select("", "", DataViewRowState.Added | DataViewRowState.ModifiedCurrent | DataViewRowState.ModifiedOriginal);

this.pipeTableAdapter.Update(rows);

rows = angleTable.Select("", "", DataViewRowState.Added | DataViewRowState.ModifiedCurrent | DataViewRowState.ModifiedOriginal);

this.angle_ironsTableAdapter.Update(rows);

rows = barsTable.Select("", "", DataViewRowState.Added | DataViewRowState.ModifiedCurrent | DataViewRowState.ModifiedOriginal);

this.barsTableAdapter.Update(rows);

rows = railTable.Select("", "", DataViewRowState.Added | DataViewRowState.ModifiedCurrent | DataViewRowState.ModifiedOriginal);

this.railTableAdapter.Update(rows);

rows = beamChannelTable.Select("", "", DataViewRowState.Added | DataViewRowState.ModifiedCurrent | DataViewRowState.ModifiedOriginal);

this.beams_channelsTableAdapter.Update(rows);

rows = givenTable.Select("", "", DataViewRowState.Added | DataViewRowState.ModifiedCurrent | DataViewRowState.ModifiedOriginal);

this.givenTableAdapter.Update(rows);

rows = circumTable.Select("", "", DataViewRowState.Added | DataViewRowState.ModifiedCurrent | DataViewRowState.ModifiedOriginal);

this.circumferenceTableAdapter.Update(rows);

}

catch (Exception ex)

{

MessageBox.Show("An error occurred while saving the date: " + ex.Message.ToString(), "Error!", MessageBoxButtons.OK);

}

}

Thanks,

cj

All Comments

Leave a comment...

  • 2 Comments
    • You say you can't save the child data. What problem are you having?
      #1; Fri, 07 Sep 2007 23:09:00 GMT
    • I also face this problem. No error occured but no new record inserted into the child table. But there is another strange event. If the child record is already inserted manually, I can update this record by BindingNavigator. Here is my code.

      System.Transactions.TransactionScope transactionscope = new System.Transactions.TransactionScope();

      using (transactionscope)

      {

      try

      {

      this.PersonInfoBindingSource.EndEdit();

      this.addressBindingSource.EndEdit();

      this.addressTableAdapter.Update(this.hrmDataSet.Address);

      this.personTableAdapter.Update(this.hrmDataSet.Person);

      transactionscope.Complete();

      this.hrmDataSet.Address.AcceptChanges();

      this.hrmDataSet.Person.AcceptChanges();

      KeyFactory.GeneralUtility.ShowMsgBox("Save Successfully");

      }

      catch (Exception ex)

      {

      KeyFactory.GeneralUtility.ShowErrorMsg(ex.Message);

      }

      }

      }

      After this.hrmDataSet.Address.AcceptChanges(); statement, there is no data in relative controls. Please help me. Thanks.

      #2; Fri, 07 Sep 2007 23:10:00 GMT