Med Amin

Med Amin

  • NA
  • 16
  • 9.5k

delete record with foreign key constraint to another table

Nov 4 2015 3:51 AM
When I tried to delete row from datagridview refer to table Famille, I get this error is :
 An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll Additional information: The DELETE statement conflicted with the REFERENCE constraint "FK_NatureCharge_Famille". The conflict occurred in database "Tresorerie", table "dbo.NatureCharge", column 'IdFam'. The statement has been terminated.
Table Famille
IdFam int
NomFam varchar(50)
Table NatureCharge
 IdNat int
NomNat varchar(50)
IdFam int
 
By the way, the Famille part can delete multiple row in datagridview. I tried to add delete the NaturCharge 1st (it begins with comment delete Nature)
The code in the rar file : 
 

an error shows with line (it is for Famille part) `cmd.ExecuteNonQuery();``

 Additional information: The DELETE statement conflicted with the REFERENCE constraint "FK_NatureCharge_Famille". The conflict occurred in database "Tresorerie", table "dbo.NatureCharge", column 'IdFam'.
 

It looks The DELETE statement doesn't seem to be correct

and the same error...

Attachment: famille.rar

Answers (5)