Click here to Skip to main content
15,889,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
how can show all database of sql server 2000 in my combo-box mean what will be code behind that

if there are more then 2 or 3 database attested in sql server and i want to show all list in list or in combo box
Posted

Try:
SQL
SELECT * FROM information_schema.tables



"this is show all table i want to show all database"


Oops! :O
VB
Dim con As New SqlConnection("Data Source=GRIFFPC\SQLEXPRESS;Integrated Security=True")
con.Open()
Dim 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

You will need to change teh instance name, and may need a UID/Password combo instead of Integrated Security.
 
Share this answer
 
v2
Comments
irfanansari 31-Jan-12 3:58am    
this is show all table i want to show all database
OriginalGriff 31-Jan-12 4:35am    
Answer updated
This[^] might help you.
 
Share this answer
 
VB
Dim conn As New SqlConnection(connString) 
Dim strSQL As String = "SELECT name FROM master.sys.databases"
Dim DA As New SqlDataAdapter(strSQL, conn)
Dim DS As New DataSet
DA.Fill(DS, "dblist")

For i = 0 To ds.Tables(0).Rows.Count - 1
cmbdb.items.add(ds.Tables(0).Rows(i).Item(0).Tostring())
Next
 
Share this answer
 
v2

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