none
Question A problem with the tableAdapterManager in a master-details form RRS feed

  • Question

  • Hello,

        I am writing an application in visual studio 2008 and I have the Dataset connecting to a SQL server 2005 with 2 tabes : Check( chkID,ChkAmount) and checkDetails (chkDetailsID,ChkID,Amount,Deduction). Each table has its ID of autonumber type.
        I have a master details form for these 2 tables when I add a new check record it is automatically assigned an temporary ID -1 untill it is saved in the database when I add a checkDetails record for this new added check it is given in the foreign Key "chkID" a value of -1 also

    The problem when I press the save button which has the following code it raises an exception at the tableAdabtermanager.UpdateAll statement


    private void checkBindingNavigatorSaveItem_Click(object sender, EventArgs e)
            {
                this.Validate();
                this.checkBindingSource.EndEdit();
                this.tableAdapterManager.UpdateAll(this.eshpetcoDBSDataSet);

            }

    The exception of type sqlexception says The INSERT statement conflicted with the FOREIGN KEY constraint "Check_CheckDetails_FK1". The conflict occurred in database "EshpetcoDBS", table "Finance.Check", column 'chkID'.
    The statement has been terminated.


    I understand that the tableadaptermanager should handle the order of inserts and updates.but I dont know why it isnt working and when I examine the values in the dataset at the exception I find that the newly added record in the check table is assigned an auto number successfully but the checkdetails not
    Saturday, July 19, 2008 10:13 AM

All replies

  •  Haytham Othman wrote:
    Hello,

        I am writing an application in visual studio 2008 and I have the Dataset connecting to a SQL server 2005 with 2 tabes : Check( chkID,ChkAmount) and checkDetails (chkDetailsID,ChkID,Amount,Deduction). Each table has its ID of autonumber type.
        I have a master details form for these 2 tables when I add a new check record it is automatically assigned an temporary ID -1 untill it is saved in the database when I add a checkDetails record for this new added check it is given in the foreign Key "chkID" a value of -1 also

    The problem when I press the save button which has the following code it raises an exception at the tableAdabtermanager.UpdateAll statement


    private void checkBindingNavigatorSaveItem_Click(object sender, EventArgs e)
            {
                this.Validate();
                this.checkBindingSource.EndEdit();
                this.tableAdapterManager.UpdateAll(this.eshpetcoDBSDataSet);

            }

    The exception of type sqlexception says The INSERT statement conflicted with the FOREIGN KEY constraint "Check_CheckDetails_FK1". The conflict occurred in database "EshpetcoDBS", table "Finance.Check", column 'chkID'.
    The statement has been terminated.


    I understand that the tableadaptermanager should handle the order of inserts and updates.but I dont know why it isnt working and when I examine the values in the dataset at the exception I find that the newly added record in the check table is assigned an auto number successfully but the checkdetails not


    Missing:
    this.checkDetailsBindingSource.EndEdit();
    Wednesday, July 23, 2008 2:20 PM