Results 1 to 2 of 2

Thread: How to update data automatically without closing/re-opening the program

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2020
    Posts
    21

    Question How to update data automatically without closing/re-opening the program

    When I insert data using "TableAdapter.InsertQuery", I would have to re-open the program for the added data to be shown in a combobox that has data binding in a specific inserted data. Like if I add "1" using insert, I would have to re-open the program for the "1" to show-up in the combobox.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    106,688

    Re: How to update data automatically without closing/re-opening the program

    Why would you have to re-open the program? How did you get the data to populate that ComboBox in the first place? Why can't you just do that again? The data doesn't appear by magic. It appears because you have code to retrieve the data and display it. You can execute that same code any time you want, e.g. on the Click of a Button or when a dialogue closes.

    That said, there's every chance that there's no need to retrieve the data again. You haven't provided enough information for us to know but there's every chance that you should not be calling that InsertQuery method in the first place. A lot of people add data to a database in one place and then are confused as to why a DataTable doesn't automatically update somewhere else in the application when what they should be doing is adding the data to the DataTable first and then saving it to the database from there. That may not be appropriate in your case - it's more likely to be so when using a DataGridView than a ComboBox - but it may be. For example, what a lot of people do is populate a DataTable from a database table in one for and display that data, then open a dialogue form that modifies the same database table, then they fret about how to sync the displayed data with the database. What they actually ought to be doing is making the changes to the local DataTable first, then saving those changes back to the database using the same data adapter or table adapter that they used to populate it in the first place. There's then no need to pull changes from the database into the DataTable because the DataTable receives the changes first and they are pushed to the database from there.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width