Click here to Skip to main content
15,885,842 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I make a combobox in Visual Basic where it can display all the database in my server?

and how do i filter it, for example
only the ones with the table "users" are only shown
help pls. and thanks!
Posted
Updated 29-Aug-14 15:30pm
v2
Comments
[no name] 29-Aug-14 21:13pm    
Open the toolbox, drag and drop a combobox control to your form, switch to the code behind, in the event handler of your choice, write some code to query the database server and get a listing of the databases in the server, take the list and add each one to the combobox.
charliedev 29-Aug-14 21:37pm    
yea but i need the code bc i dont know how to diplay filtered databases
[no name] 29-Aug-14 22:01pm    
Then you should get started writing the code. We are not here to write code for you. You display the filtered database in exactly the same manner as a non-filtered database AND in exactly the same way that you have already been told in your previous "questions".
charliedev 1-Sep-14 2:18am    
.

1 solution

Try this:
VB
Using con As New SqlConnection(strConnect)
	con.Open()
	Using cmd As New SqlCommand("sp_databases", con)
		cmd.CommandType = CommandType.StoredProcedure
		Dim read As SqlDataReader = cmd.ExecuteReader()
		While read.Read()
			Console.WriteLine(DirectCast(read("DATABASE_NAME"), String))
		End While
	End Using
End Using
All you have to do is sort out getting the info into the combobox.

If you use a DataView as the Combobox DateSource, you should be able to apply filters in the normal way (I haven't tried it with a Combobox, but it works fine with DataGridViews.)

"i have a problem, i dont know how to filter databases according to the tables inside them. Example i only want to show databases with the table "user" inside. How do i do that? thanks"

You will need to query each DB in turn.
Try connecting to the DB and using:
SQL
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'

Alternatively without specifying the DB in the connection:
SQL
USE yourDBName; SELECT name FROM sys.Tables
 
Share this answer
 
v2
Comments
charliedev 1-Sep-14 2:31am    
i have a problem, i dont know how to filter databases according to the tables inside them. Example i only want to show databases with the table "user" inside. How do i do that? thanks
OriginalGriff 1-Sep-14 5:15am    
Answer updated

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900