VB 2005 The record cannot be deleted or changed because table YYY includes related records

C

Craig Grell

I have a simple parent child table setup using MS Access

I keep getting this error

The record cannot be deleted or changed because table YYY includes related
records

I am not updating the primary key or changing it.

I looked at the code in the Dataset.Designer.vb

For some reason the primary key is trying to update in the updateCommand. I
assume this is why I keep getting this error

How can I get the code generator to not add the primary key to the Update
Statement?

Or if i manually edit the update statement how can i make the code generator
leave it alone?

Thanks
 
R

Rick

First, make sure the table in the Access database is properly keyed. If
the table doesn't have a primary key, any updates will fail because all
the tools involved use the primary key to find the appropriate record.

Second, make sure your relationships are set up correctly in the
database. Pay particular attention to the update / delete and
referential integrity rules.

When you design your dataset, do so by dragging the table from Data
Connections in the Server Explorer. This will automatically generate
the data set that will work with your database table, well 99.999%. (If
your table contains an auto incrementing primary key, you should set
the DataSet.FieldName properties AutoIncrement = true,
AutoIncrementSeed = -1, AutoIncrementStep = -1) (These properties may
be your problem)

After that's all said and done, unless you have cascading deletes setup
on the relationship between table1 and table2, a delete from a lookup
table will cause this error.

I.e. if you try to delete a record from a ProductTypes table, it will
error if the Products table contains a record that refer's to the
ProductType you are trying to delete.

-Rick
 
C

Craig Grell

parent table has a primary key parent_id
child table has a primary key parent_id, child_id
foreign key is defined for parent_id

dataset generated with all the propery keys and relationships

I get the error when trying to update the parent table unless i manually
change the Dataset.Designer.vb to remove the parent_id from the set portion
of the update command.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top