Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ForeignKeyConstraint issues

Status
Not open for further replies.

ethorn10

Programmer
Feb 18, 2003
406
0
0
US
Unfortunately, I don't have any code at hand to post (it's on the dev system) but I have a question for you experts. First things first, c# and a strongly-typed dataset to an Access database. Anyway, I'm getting the error:

ForeignKeyConstraint <Name_of_constraint> requires the child key values (<values>) to exist in the parent table.

There are 3 child tables that need the PK of the parent table. The way the code is supposed to work is that it calls Delete() for the DataRow and then deletes all rows in the child tables and then finally on the parent. When finding the "deleted" rows for the first child table (DataTable.Select(null, null, DataViewRowState.Deleted)), I notice that the ItemArray says it threw an exception of type 'System.Data.DeletedRowInaccessibleException'

Anyway, I apologize for being long-winded on this as I'm not sure where to start with it...it seems as though the parent information is being deleted before it should be. Oh, and this is inherited code [bigglasses]
 
If access has cascading deletes (and the db is configured to use them) delete the parent and children will automatically be deleted. if not you need to delete the children first and then the parent.

[tt]System.Data.DeletedRowInaccessibleException[/tt] says it all. You are trying to access a row that has been deleted. get the values from the row before deleting.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Well...see this is where I wasn't sure how to word the "question" (more like a scenario). I was under the impression the DataRow.Delete() doesn't actually delete from the database, but rather flags the items in the dataset for deletion. So the code calls the DataRow.Delete() and then begins with the child tables before ending with the parent (this process takes the table name and finds those rows flagged for deletion and calls a DataAdapter.Update with the DataRow[]).
 
that i'm not sure of. i don't use strongly typed dataset or data adapters.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top