CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Jul 2008
    Posts
    18

    More fun with Databases...

    Ok, so I'm using the Northwind Database (an example that comes with Microsoft Access, or you can download it from Microsoft) and creating a "front end" for it as kind of an experimental project to learn of database design/programming/access/etc.

    The problem I'm encountering is that there seems to be a reference from the "Customers" table to the "Orders" table. When I click on my "delete" link to delete a row in the DataTable it works fine until my adapter.update() is called. Once that is called, I get a return error message saying:
    OleDbException was unhandled
    The record cannot be deleted or changed because table 'Orders' includes related records.
    My Question is this: I can handle the OleDbException, but what I need to know is how to programmatically step through the 'Orders' table and delete any entry in reference to Customer table via CustomerID field. And also, how can I tell which tables support referential integrity with which other tables?

    Btw, it is an ACCESS database and I'm using System.Data and System.Data.OleDb with a datatable/adapter/commandbuilder

    Any help would be appreciated.
    - dizuane

  2. #2
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: More fun with Databases...

    Quote Originally Posted by dizuane
    ...
    Btw, it is an ACCESS database and I'm using System.Data and System.Data.OleDb with a datatable/adapter/commandbuilder ....
    In each access database you can have a look to a table which graphically shows you how the tables are connected simple look at it which tables are related to each other. If there are no tables added to this 'relations table' ( dont know english name ) simple add the whole database tables to it and look what you will see. If you arrange the customers relations in a way that deleting the customer also deletes his orders and all other records where the CustomerId is used a s a foreign key then it should work. If you dont connect them this way then you first need to delete all orders of the customer and all other recordsets where his ID is used as a key before you are able to delete the customer itself.
    Generally in a one to many relation you can only delete the 'one' ifyou delete all of the 'many' which are related to it.
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured