none
What's the best way to make permanent the changes made to a DataSet? RRS feed

  • Question

  • What's the best way to make permanent (commit the changes back to the database) the changes made to a DataSet/DataTable? I've seen that the DataSet/DataTable class has an AcceptChanges() method and the DataSet can also be updated using a DataAdapter, what's the best way to do it given that DataAdapters are limited to update single tables with no joins? Am I missing another way to do it much more efficient and standardized than those two? What would be the best way if we weren't using an SQL Server data provider? (I'm not well versed on .net so bear with me :) )
    Friday, May 28, 2010 7:28 PM

Answers

All replies

  • A couple of comments:

    1) You don't want to use .AcceptChanges() because what this does is make it so the DataSet/DataTable has NO changes (and subsequent attempts to save changes to the database would find no changes to send to the database).

    2) DataAdpaters are NOT limited to updating single tables (you're probably thinking of the TableAdapter, which is different).

    That said, take a look at the 3-part DataAccess series on my blog. You may get some ideas that'll help:

    http://geek-goddess-bonnie.blogspot.com/2009/09/dataaccess-part-i.html
    http://geek-goddess-bonnie.blogspot.com/2009/10/dataaccess-part-ii.html
    http://geek-goddess-bonnie.blogspot.com/2009/10/dataaccess-part-iii.html


    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    • Marked as answer by rpgmaker Tuesday, June 1, 2010 2:24 AM
    Sunday, May 30, 2010 12:19 AM
  • Thanks for the links, I will read them. So if I'm getting it right, when I do an .AcceptChanges() what it does is to flag the changes made to the datatable as if they aren't supposed to be propagated back to the data source? I thought it was the disconnected analogue of the "commit" command...

    Regarding my comment about DataAdapters being limited to a single table I re-read the material from which I got the idea and it was talking about CommandBuilders. I assumed that CommandBuilders were the only way to build update commands to the DataAdapter (silly me, I know). Could you provide me an example of an UpdateCommand command, is it just like a common sql update command or does it have some especial relation with the other commands?

    Monday, May 31, 2010 4:12 PM
  • So if I'm getting it right, when I do an .AcceptChanges() what it does is to flag the changes made to the datatable as if they aren't supposed to be propagated back to the data source

    Right.

    I assumed that CommandBuilders were the only way to build update commands to the DataAdapter (silly me, I know). Could you provide me an example of an UpdateCommand command, is it just like a common sql update command or does it have some especial relation with the other commands?

    See the first of my blog posts ... it shows how to set up the update commands without using a CommandBuilder, and other options ... it should at least give you some good ideas.


    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    Monday, May 31, 2010 8:03 PM
  • Ok, thanks very much.
    Tuesday, June 1, 2010 2:24 AM
  • You're welcome ... let me know if you have any other questions. =0)
    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    Saturday, June 5, 2010 4:20 PM