none
How to save two related datatable in database? RRS feed

  • Question

  • Hi to all,

     

    I required to save two related datatables of dataset in database. Parent and Child relation exists between two tables in dataset.

    Is it possible in .net to save two datatables having relation of child and parent of a dataset in a database at once instead of using one by one row of each datatables.

     

    If it is possible then please let me know how to do it. Urgently required.

     

    Thanks

    Sandeep Soni

    Friday, December 28, 2007 10:19 AM

Answers

  • In this case you need to follow a series of steps that makes sure the changes are saved in the right order.

    Suppose you're working with a Customer/Order relationship. In this case you need to add any new parents before the children and delete any deleted children before any deleted parents. If you're using VS 2008 you can use the new TableAdapter manager to assist in these operations. I have a whitepaper that shows how to work with hierarchical relationships on http://www.developer.com/db/article.php/10920_3693236_1. This article was written before the TAM was created.

     

    Saturday, December 29, 2007 7:40 PM
    Moderator

All replies

  •  

     

     

    SqlDataAdapter adp = new SqlDataAdapter();

     

    System.Data.DataSet ds = new System.Data.DataSet();

     

    adp.fill(ds);

     

    // do data upatations  

     

    adp.Update(ds);

     

     

    Saturday, December 29, 2007 5:22 AM
  • In this case you need to follow a series of steps that makes sure the changes are saved in the right order.

    Suppose you're working with a Customer/Order relationship. In this case you need to add any new parents before the children and delete any deleted children before any deleted parents. If you're using VS 2008 you can use the new TableAdapter manager to assist in these operations. I have a whitepaper that shows how to work with hierarchical relationships on http://www.developer.com/db/article.php/10920_3693236_1. This article was written before the TAM was created.

     

    Saturday, December 29, 2007 7:40 PM
    Moderator