How to keep data on the client till it needs to update the database? RRS feed

  • Question

  • I'm starting a windows forms application using .net 3.5.

    Once the user logs I will make a call to the DB to bring down the needed data. Now if they edit the data I want the data to be made on the client so the form reflects those changes but I don't want the database to update until the user clicks the save button.  Once that is done I only need to make a one way trip to the db to update the changes since the exact changes should already be on the client.

    I would truly appreciate your help in starting this out correctly.  This is a method I was instructed to find and use.  If you think there is a cleaner way please let me know.

    Thank you,


    • Moved by CoolDadTx Tuesday, July 9, 2013 7:09 PM Data related
    Tuesday, July 9, 2013 5:02 PM


All replies

  • Can you elaborate your scenario ?
    Tuesday, July 9, 2013 5:30 PM
  • Abhishek,

    When a user runs the application they will log in and on the next screen they will get the data that is specific to them.  Now at this point I want the data to be on the client side so there isn't numerous back and forth with the server.   Now the user starts to edit his data and then clicks save I only want to send an update statement to the database.  Since the client data already reflects his updates there is no need to bring data back from the database.

    Please let me know if I should elaborate more.

    Thank you

    Tuesday, July 9, 2013 5:41 PM
  • Personally, I think the best way to handle this is with your own DataAccess classes and avoid using the TableAdapter (that makes extra trips to the database, which you, rightly so, want to avoid). Take a look at my 3-part series on Data Access for some basic ideas. I'm using a SQL database, but the same would apply to other databases (except you'd use OleDb classes instead of Sql classes):

    Each post adds extra complexity to the Data Access classes, but more flexiblity. The first post is enough to get you going in the right direction and give you a general idea of the concept, but the second post is more useful. The third post gets into using anonymous delegates..

    ~~Bonnie Berent DeWitt [C# MVP]

    • Edited by BonnieBMVP Wednesday, July 10, 2013 1:26 AM Make links actual links. Didn't used to have to do this!!!!
    • Marked as answer by Chester HongModerator Thursday, July 18, 2013 11:36 PM
    Wednesday, July 10, 2013 1:24 AM
  • Hi 

    I think for the point "data to be on the client side" you dont need to do anything extra. Once you get the data on the client . You can store it in any variable and that will remain on the client memory unless and until it goes out of context. 

    On click of save button, if you are binding your grid with the datatable then just call the datatable.AcceptChanges() after the saving.

    I hope you are asking for this.

    Wednesday, July 10, 2013 1:25 AM