Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change connection refresh vb.net form

Status
Not open for further replies.

diamondsc

Programmer
Jun 28, 2001
44
0
0
US
I am using Visual Studio 2005 and visual basic.net. I have a vb form that contains a tableadapter bound to an Access table. On the form is a textbox that displays the contents of a specific field in the Access table. This works fine.

On the same form I allow the user to choose a different Access database (one that has an identical schema). I use the following code to do this:

Me.OpenFileDialog.ShowDialog()
If Me.OpenFileDialog.FileName <> "" Then

TC.My.Settings.TCDBConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Me.OpenFileDialog.FileName

Else

MessageBox.Show("The database connection has not changed.", "Choose Database", MessageBoxButtons.OK, MessageBoxIcon.Information)

End If


This also works. However, even though the data in the newly chosen database is different, the content of the textbox does not change until the form is closed and reopened.

My question is, once I change the connection, how do I refresh the databindings, tableadapter, bindingsource, etc. or whatever I need to refresh to display the correct data in the textbox?

Thanks.
 
Textbox.clear

After they choose the new source, use the clear method and then repopulate it with the new data. If it's an issue with the data not refreshing in the in the DataAdapter then that's because you're not setting it to nothing before attempting to recreate it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top