0

I have a parent table named "Devis" and its child table named "LigneDevis", I want to insert data into two tables using devisBindingSource and ligneDevisBindingSource, here the Update code :

private void devisBindingNavigatorSaveItem_Click(object sender, EventArgs e)
    {            
        this.Validate();            
        this.devisBindingSource.EndEdit();            
        this.ligneDevisBindingSource.EndEdit();            
        this.tableAdapterManager.UpdateAll(this.dBDataSet);                        
    }

When I try to insert new rows in both tables, an error occured :

System.Data.SqlServerCe.SqlCeException was unhandled Message=Impossible d'insérer une valeur de clé étrangère, car il n'existe pas de valeur de clé primaire correspondante. [ Foreign key constraint name = Ligne_Devis ]

My question is : is there a solution to resolve Foreign Key constraint problem ? Thanks.

aEk BKF
  • 131
  • 1
  • 2
  • 15

1 Answers1

0

You can ignore Foreign key constrains of a DataSet using EnforceConstraints property.

DataSet.EnforceConstraints = false;

http://msdn.microsoft.com/en-us/library/system.data.dataset.enforceconstraints.aspx

Manoj De Mel
  • 927
  • 9
  • 16