Skip to main content
gamedev.net
🔒 Locked

Cascade Delete Problem...

Started by Elwren 3 replies 650+ views
Original Post
Elwren
Elwren
Hey, I am working on a program involving a database and I do not know that much regarding database programming. Currently I am connecting to a MS Access database with OleDB and am using the OleDbCommandBuilder to have it make all my INSERT/MODIFY/DELETE commands. However, I have tables with various foreign keys in them and I need to perform a cascade delete to delete the parent and all its children in the different tables. I get an error when just using my regular delete method, which is: // CODE DataTable deletedContentTable = myDataSet.Tables["TABLE_NAME"].GetChanges(DataRowState.Deleted); myDataAdapter.Update(deletedContentTable); deletedContentTable.Dispose(); myDataSet.AcceptChanges(); // END CODE This does not currently perform a cascade delete. Does anyone know how I can force it or turn on cascade delete with the OleDbCommandBuilder? Or do I have just have to write my own special SQL commands to do these DELETE's? Thanks for the help.
ROBERTREAD1
ROBERTREAD1
I find its often best not to use cascade delete.

It's not much more work, plus you get to see exactly what goes on.

Elwren
Elwren
What other option is there other than to use cascade delete? I need to delete a record out of a table and I cannot because of foreign key issues. What else can I do? Any suggestion is welcome.
evolutional
evolutional
Whenever I need to do this I write a SQL script to find all the values for these FKs and wipe out these references. In the systems I'm used to dealing with it can be quite painful :(
ROBERTREAD1
ROBERTREAD1
Say you are deleting a car.

DELETE FROM CarPart WHERE CarPart.CarID = ...

then

DELETE FROM Car WHERE Car.ID = ...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.