Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Typed dataset with cascade delete using TableAdapter

Typed dataset with cascade delete using TableAdapter

Scheduled Pinned Locked Moved Database
csharpcssdatabasehelptutorial
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JensB
    wrote on last edited by
    #1

    Hi, We have implemented a Windows c# application using a typed dataset (ADO.NET) I've modified the relation so the childs get deleted when the parent is deleted. Delete action: cascade. In the function where I process all the changes in the dataset (Dataset.GetChanges()), I create for every table 1 adapter & call the .Update() function. When the first adapter (for parent) is created & called the .Update() function, the parent and all its childs are deleted due to the relationship (Delete action: cascade) A few lines further on, the adapter of the childs are called and the .Update() function throws an exception because the child is already deleted on the DB! This is very ennoying and I really don't know how to solve this problem. Any idea how to solve this? I tested it out with my own SqlCommand object and the deletion of the parent & childs did not cause any problems. I'd really love to keep the relationship so the childs get deleted automatically. This allows me to write less code :) Best regards, Jens

    K 1 Reply Last reply
    0
    • J JensB

      Hi, We have implemented a Windows c# application using a typed dataset (ADO.NET) I've modified the relation so the childs get deleted when the parent is deleted. Delete action: cascade. In the function where I process all the changes in the dataset (Dataset.GetChanges()), I create for every table 1 adapter & call the .Update() function. When the first adapter (for parent) is created & called the .Update() function, the parent and all its childs are deleted due to the relationship (Delete action: cascade) A few lines further on, the adapter of the childs are called and the .Update() function throws an exception because the child is already deleted on the DB! This is very ennoying and I really don't know how to solve this problem. Any idea how to solve this? I tested it out with my own SqlCommand object and the deletion of the parent & childs did not cause any problems. I'd really love to keep the relationship so the childs get deleted automatically. This allows me to write less code :) Best regards, Jens

      K Offline
      K Offline
      Keith Malwitz
      wrote on last edited by
      #2

      I think your problem is with the order you are performing updates. You should make sure you perform updates in the correct order. Check out this MSDN walkthrough: http://msdn2.microsoft.com/en-us/library/4esb49b4.aspx[^] Hope this helps.

      J 1 Reply Last reply
      0
      • K Keith Malwitz

        I think your problem is with the order you are performing updates. You should make sure you perform updates in the correct order. Check out this MSDN walkthrough: http://msdn2.microsoft.com/en-us/library/4esb49b4.aspx[^] Hope this helps.

        J Offline
        J Offline
        JensB
        wrote on last edited by
        #3

        Hi, Performing the updates in the correct order is not a good solution aswell. I have put the table adapter update of parent at the end, but this comes with another problem. Let's say you have to create the parent, the table adapter needs to first do the inserts of the parents, otherwise the children won't be added because of the relationship! Any other solutions? Best regards, Jens

        K 1 Reply Last reply
        0
        • J JensB

          Hi, Performing the updates in the correct order is not a good solution aswell. I have put the table adapter update of parent at the end, but this comes with another problem. Let's say you have to create the parent, the table adapter needs to first do the inserts of the parents, otherwise the children won't be added because of the relationship! Any other solutions? Best regards, Jens

          K Offline
          K Offline
          Keith Malwitz
          wrote on last edited by
          #4

          Perhaps I was not clear enough in my previous post. When updating a data source containing multiple related tables, you should update in this order: 1. ChildTable Deleted Records 2. New, Modified, and Deleted ParentTable Records 3. New ChildTable Records 4. Modified ChildTable Records This order ensures that updates can be performed properly, taking into account the relationship between the tables. The link in my previous post will walk you through how to update records based on their status (Added, Modified, Deleted). Hope this helps.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups