title: conflicted with the FOREIGN KEY constraint "FK_tableName". The conflict occurred in database "databaseName", table "tableName", column 'id'
body: <p>I am trying to fill the table " tbl_detail_commande" with data from a form . But when I want to insert the data in database , it gives me this error :</p>
  
  <pre><code>conflicted with the FOREIGN KEY constraint FK_tbl_detail_commande_tbl_detail_demande_achat". 
  The conflict occurred in database "Gestion Commercial Officielle",  
  table"dbo.tbl_detail_demande_achat", column 'id'.The statement has been terminated.'
  </code></pre>
  
  <p><strong><em>I tried some solutions :</em></strong></p>
  
  <p>1-checking my foreign key relations</p>
  
  <p>2-enable identity_insert  on table "tbl_detail_commande"</p>
  
  <p>But I still get the same error .</p>
  
  <p><strong><em>Here is my tables</em></strong> : <a href="https://i.stack.imgur.com/a8mjG.png" rel="nofollow noreferrer">click her to show tables diagram</a></p>
  
  <p><strong><em>Also here is the code I use to insert data into my database :</em></strong></p>
  
  <pre><code>String numero_demande = demande.Text;
  tbl_detail_commande dc = new tbl_detail_commande();
  
  var id = (from c in db.tbl_detail_commande orderby c.id_detail_commande descending 
  select c.id_detail_commande).FirstOrDefault(); 
  int valueId = Convert.ToInt32(id.ToString()) + 1;
  dc.id_detail_commande = valueId;
  
  var q = (from cc in db.tbl_detail_demande_achat where cc.id_demande == Convert.ToInt32(numero_demande)
  select cc.id).Distinct().SingleOrDefault(); 
  dc.id_detail_demande = Convert.ToInt32(q);
  dc.code_article = Convert.ToInt32(code_article.Text);
  dc.id_commande= Convert.ToInt32(num_commande.Text);  
  db.tbl_detail_commande.InsertOnSubmit(dc); 
  db.SubmitChanges();
  </code></pre>
  
  <p>I dont not what is the problem I just kept turning in circles.Can someone help me please or tell me what I kept doing wrong ?                </p>