How to choose available databases ?

wilmoslee

Member
Joined
Mar 12, 2010
Messages
9
Programming Experience
1-3
Hi prof..

I hv a question.. I would like to create a login form, user able to select defferent databases from the listbox.

Is tht possible?

thanks.
 
List of databases

Which database server are you running? If its MySQL then execute the query
VB.NET:
show DATABASES;
It will return a list of databases available on the server.

To get a similar result in MS-SQL, use:
VB.NET:
sp_databases;

And the you populate a combobox or something with the results.
When the log-in button is clicked, a connection stirng must be built, using whichever database is selected in the combobox
 
Last edited:
Pls adv

Thanks for the reply! I use the select statement below :
select * from sys.databases to get all the available databases in my server.

But I hv this question abt the dataset or gridview connection..

For example. in form a, i used a gridview to display patient name, so the connecting string has been defined to database A, Patient table. for example. Now, If i change the the login connection to different database, let say B, will the gridview auto update the connection string to connect to the database B, or it will still connect to the database A?

Many thanks.
 
When you create a connection object, you can specify a connection string as a parameter. Whichever database the new connection object and connection string points to will be the one you will get the data from.

What I would do next is fill a DataSet with whatever data you want (using your newly opened connection), and make sure to set the DataSource property of the DataGridView to point to the new DataSet. (or something like that)
 
Yikes.. this is the 4th time this week that this question has been asked - has someone set it as a class project or something?

Probably the easiest way, after reading the DW3 link in my signature (section Creating a Simple Data App) so you know what a tableadapter is, is to set the connection the tableadapter uses with:

myTableAdapter.Connection.ConnectionString = "blahblah"
 
Back
Top