How to refresh dataset after I've changed my connection string? RRS feed

  • Question

  • I have a OpenFileDialog in my program that I use to change my databases if necessary. I can succesfully change my connection string but now I need to know how to make the change affect my databound controls immediattely. Now I need to restart it before the changes will work.


    Thanks in advance!

    Monday, August 13, 2007 11:32 AM

All replies

  • There is nothing built into the framework to do this.
    You are going to have to go to each control and re-bind it with a new dataset by creating a new sqlcommand, new dataadpater and calling dataadapter.Fill methods again.

    On each form that needs this I would create a method called RefreshData() that loads the data using the currently configured connectionstring and binds all of the controls from the refreshed data.

    If you're refreshing from code outside of the form like from an MDIParent form, you can create an Interface with one call Sub RefreshData and have each form that needs it implement this interface.  Then loop through each form and call the RefreshData interface method external to the form.

    Monday, August 13, 2007 3:05 PM