none
how to insert dataset into a database which is populated from another database? RRS feed

  • Question

  • i wanted to ask how can i actually insert a dataset populated from a database to another database in c#?

    i've tried using DataAdapter with the function Update which looks like adapter.Update(dataset, tablename)

    but somehow, it would not update the empty database as there is no changes on the dataset.

    my purpose is just to copy all the data from a database and insert it to another database without any changes.

    am i at the wrong direction? or is there any good reference that i can refer to?

    thanks in advance.

    Friday, July 29, 2011 8:09 AM

Answers

  • You'll first want to iterate through all the DataRows in your DataTable and use the DataRow.SetAdded() method to change the row's DataRowState. Then your 2nd DataAdapter will think that the Rows need to be added.
    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    • Marked as answer by Jim6123 Monday, August 1, 2011 3:19 AM
    Monday, August 1, 2011 1:49 AM

All replies

  • just use another adapter which connects to other database,
    Please mark this post as answer if it solved your problem. Happy Programming! 
    Friday, July 29, 2011 1:58 PM
  • ya..i've tried..

    i've used a adapter to fill a dataset from a database. then i wanted to insert this dataset to another database.

    the insertion part, how can i do so in precise? any reference?

     

    Friday, July 29, 2011 3:24 PM
  • You'll first want to iterate through all the DataRows in your DataTable and use the DataRow.SetAdded() method to change the row's DataRowState. Then your 2nd DataAdapter will think that the Rows need to be added.
    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    • Marked as answer by Jim6123 Monday, August 1, 2011 3:19 AM
    Monday, August 1, 2011 1:49 AM
  • Hey BonnieB,

    It's just amazing, i've get my program working with your advise. what i knew of the adapter.update will only update those rows which are modified. what if the rows are not modified, then the update would not have commit any changes to the database. that's why im stuck on this problem for a long time. but you've saved my day. thanks alot

    Monday, August 1, 2011 3:19 AM
  • You're welcome, Jim ... glad I could help!  =0)
    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    Monday, August 1, 2011 4:41 AM