TableAdapter cannot delete record because of related records

I have an application that uses an Access database and the database has a PATIENTS table and a DOCTORS table. Of course, the PATIENTS table has a foreign key relationship with the DOCTORS table to identify who the patients doctor is.

Now, when my application starts I'm pulling in the DOCTORS table using a TableAdapter and BindingSource (TableAdapter.Fill(BindingSource)) and I'm also pulling in the PATIENTS data but the patients data is coming in as a query that joins the doctor. This all works pretty good since I can view, add, and edit data.

Now, my problem is with deleting. If I add a brand new record to DOCTORS and then try to delete this record I get a message: "The record cannot be deleted or changed because table 'PATIENTS' includes related records."

Why do I get this message? I understand there is a relationship with these tables but there shouldn't be any related patient data for a brand new doctor.

Also, I am actually able to update a doctor record (change his name) but it is not reflected in the patient data unless I refill the binding source; is there a way for this to update automatically?
hmstechsupportAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

drypzCommented:
Hi! In your access database, modify the relationship of those tables.  Remove the cascade effect.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sybeCommented:
> "The record cannot be deleted or changed because table 'PATIENTS' includes related records."

Have you looked in your database which patients are related?
0
hmstechsupportAuthor Commented:
Thanks for the replies.

drypz: There is no cascading effect in the database relationship. However, there is a relationship with "Enforce Referential Integrity", relationship type "One-To-Many". Looks good to me.

sybe: There are no patient records related to the record I'm trying to delete becaue I just added the doctor record. I did check the database just to make sure and there is absolutely no related records.
0
hmstechsupportAuthor Commented:
So I've managed to move past this issue, the problem was that I was using the wrong BindingSource so it wasn't trying to remove the right record, DUH on my part.

Thanks for the replies, partial rewards for everyone!
0
hmstechsupportAuthor Commented:
Responses were good but in the end the solution was to fix my bad coding.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.