0

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 table, and two detail 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);
    }

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);
    }

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);

This is driving me crazy!

John Saunders
  • 160,644
  • 26
  • 247
  • 397
bbaley
  • 199
  • 6
  • 22

1 Answers1

0

What I would recommend to do in this situation: check if your changes appearing in the DataSet by calling

this.dsShiftReport.GetChanges();

So that you will know if the changes are at least reflected within the DataSet.

I assume that you have some kind of a DataGridView control on your form and binding your tables to the DataGridView. I might be wrong (I haven't worked with WinForms and DataSets for a while) but what if you hit "enter" and/or try to move to another Row within your DataGridView before you hit "Save" button - just wondering if your data will get saved in this case.

Mikhail
  • 898
  • 7
  • 21