Deleting record causes error

MartinaL

Active member
Joined
Jun 13, 2006
Messages
30
Programming Experience
1-3
I am getting the following error when I try and delete a record from a table called Course from a windows form;

"DELETE statement conflicted with COLUMN REFERENCE constraint 'FK_tbl_CourseCategory_tbl_Courses'. The conflict occurred in database 'cams', table 'tbl_CourseCategory', column 'CourseID'.
The statement has been terminated."

The table Courses has a foreign key in the table Categories which has a foreign key in the table Competencies.

WHen I click the delete button for the Courses Datagrid all the course is deleted as are the records on the screen in the Categories datagrid and the Competencies datagrid but when I click save I get the above error
 
Alter the order of your Update statements so that you are passing datatables in for update in order of child -> parent


i.e. you have tables GrandMother, Mother, Daughter. When you delete a record from grandmother, the referenced records are deleted from mother, and daughter in the dataset. If your database doesnt cascade deletes then the order of code MUST be:

daughterTA.Update(daughterDT)
motherTA.Update(motherDT)
grandmotherTA.Update(grandmotherDT)

you cannot update (send to db) grandma first because it would leave orphaned daughter records

either modify the database to cascade deletes or delete from child up, not parent down
 
Back
Top