c# ado.net bindingsource master-detail problems saving child records to database

bbaley
bbaley used Ask the Experts™
on
Hi all,
At first glance I realize this question has been asked many times - and I think I have read/searched many of them - and I have tried very hard to check every suggestion I found -

Perhaps I just need another pair of eyes ?

The issue is this :
I have a master<parent> table, and two detail<child> tables. They are defined in my datasource exactly as in the database, with identical relationships and key/FK fields/types.

I can enter data into the tables manually and I get the expected results when querying (left join etc). Also, I can then see the records correctly in the application - joined to the correct parent record.

However, only one of these tables/BindingSources is working correctly.
I have looked everywhere I know to look and can't see a difference ?

The BargeDetails tablebinding source works perfectly.
The ShiftDeadTime does not save / insert records to the database.

I have checked and the bindingsource.count = 1, and the underlying bindingsource.current has the expected values.

A SQL Trace shows no attempt to insert/update.


I am using Visual Studio 2010, ADO.NET, .NET 4 and WinForms, and SQL Server 2008.
The datasource was designed, not code first using the designer.
I changed the detail bindingsources to point at the correct datasource/datamember=FK...

In my _Load() - I have the order of the ta.fill()s correct seemingly;

private void frmShiftReport_Load(object sender, EventArgs e)
        {
             this.shiftsTableAdapter.Fill(this.dsShiftReport.Shifts);
            this.shiftDeadTimeTableAdapter.Fill(this.dsShiftReport.ShiftDeadTime);            
            this.bargeDetailTableAdapter.Fill(this.dsShiftReport.BargeDetail);

            this.vw_BargeLookupTableAdapter.Fill(this.dsShiftReport.vw_BargeLookup);
            this.vw_CommodityLookupTableAdapter.Fill(this.dsShiftReport.vw_CommodityLookup);
        }

Open in new window



The bindingsources appear to be setup the same;

shiftDeadTimeBindingSource
 datasource =    shiftsBindingSource1
 datamember =    FK_ShiftDeadTime_Shifts

bargeDetailBindingSource
datasource =     shiftsBindingSource1
datamember =     FK_BargeDetail_Shifts

dgShiftDeadTime
datasource = shiftDeadTimeBindingSource


In my click/save events it LOOKS like I have the correct/similar EndEdit()s and UpdateAll();

        // barge details
        private void shiftsBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.shiftsBindingSource1.EndEdit();
            this.bargeDetailBindingSource.EndEdit();

            this.tableAdapterManager.UpdateAll(this.dsShiftReport);
        }


        // shiftDeadTime
        private void toolStripButton8_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.shiftsBindingSource1.EndEdit();
            this.shiftDeadTimeBindingSource.EndEdit();

            this.tableAdapterManager.UpdateAll(this.dsShiftReport);
        }

Open in new window


And finally, in the datasource.designer.cs -
the two relations/constraints appear to be setup identically ;

            fkc = new global::System.Data.ForeignKeyConstraint("FK_BargeDetail_Shifts", new global::System.Data.DataColumn[] {
                        this.tableShifts.IDColumn}, new global::System.Data.DataColumn[] {
                        this.tableBargeDetail.ShiftIDColumn});
        this.tableBargeDetail.Constraints.Add(fkc);
        fkc.AcceptRejectRule = global::System.Data.AcceptRejectRule.None;
        fkc.DeleteRule = global::System.Data.Rule.Cascade;
        fkc.UpdateRule = global::System.Data.Rule.Cascade;

        fkc = new global::System.Data.ForeignKeyConstraint("FK_ShiftDeadTime_Shifts", new global::System.Data.DataColumn[] {
                        this.tableShifts.IDColumn}, new global::System.Data.DataColumn[] {
                        this.tableShiftDeadTime.ShiftIDColumn});
        this.tableShiftDeadTime.Constraints.Add(fkc);
        fkc.AcceptRejectRule = global::System.Data.AcceptRejectRule.None;
        fkc.DeleteRule = global::System.Data.Rule.Cascade;
        fkc.UpdateRule = global::System.Data.Rule.Cascade;

        this.relationFK_BargeDetail_Shifts = new global::System.Data.DataRelation("FK_BargeDetail_Shifts", new global::System.Data.DataColumn[] {
                        this.tableShifts.IDColumn}, new global::System.Data.DataColumn[] {
                        this.tableBargeDetail.ShiftIDColumn}, false);
        this.Relations.Add(this.relationFK_BargeDetail_Shifts);

        this.relationFK_ShiftDeadTime_Shifts = new global::System.Data.DataRelation("FK_ShiftDeadTime_Shifts", new global::System.Data.DataColumn[] {
                        this.tableShifts.IDColumn}, new global::System.Data.DataColumn[] {
                        this.tableShiftDeadTime.ShiftIDColumn}, false);
        this.Relations.Add(this.relationFK_ShiftDeadTime_Shifts);

Open in new window



This is drving me crazy! so any help and extra viewing to point out where I am being blind or dumb is MOST appreciated !
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Solved:

I updated the table in the database, and refreshed the dataset.

This appears to drop the TableAdapterManager reference to the individual TableAdapter.

Odd - when you edit the TableAdapterManager - it still has a <named>TableAdapter - however no value pointing to <it>.

So it seems to be a matter of "change anything, re-edit the TabelAdapterManager".

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial