1

The DeleteCommand for my SqlDataSource is giving me some issues because of primary/foreign keys I believe.

Here is the DeleteCommand:

DeleteCommand="delete from jm_AccountWorkFlowSteps where id = @stepID;delete from jm_AccountWorkFlowProcedure where id = @workFlowProcedureID;DELETE FROM [JM_AccountWorkFlowDetail] WHERE [workID] = @workID"

Now when I run this code in SQL it works just fine, the procedures table is deleted first which allows the WorkFlowDetail row to be deleted. But when I plug in the same SQL into the DeleteCommand it gives me the following error:

The DELETE statement conflicted with the REFERENCE constraint "FK_jm_AccountWorkFlowProcedure_jm_AccountWorkFlowProcedure". The conflict occurred in database "Collect2000", table "dbo.jm_AccountWorkFlowProcedure", column 'workID'.
The statement has been terminated.

Why would this work as expected in SQL but not in the DeleteCommand? And how can I get it to work?

The Procedure table has a foreign key to the WorkFlowTable so I am trying to delete this row first so it allows me to delete the other table row after.

James Wilson
  • 5,074
  • 16
  • 63
  • 122
  • From which table are you deleting, is it the parent or the child?, is it connected to other tables? Also about SSMS, it happened here too http://stackoverflow.com/questions/3776269/i-got-error-the-delete-statement-conflicted-with-the-reference-constraint – NoChance Nov 14 '13 at 06:01
  • @EmmadKareem I am trying to delete from three tables. I am trying to delete from the foreign keyed table first and the primary keyed table last which works in SSMS but not from the DeleteCommand. The only think I can think of it is tries to run each delete statement independently through a transaction and when it cant it just errors. I was able to find a work around however using GV_RowUpdating. Just seems odd. – James Wilson Nov 14 '13 at 17:57
  • Yes, I can't figure this one at all! – NoChance Nov 14 '13 at 19:52

0 Answers0