Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all

i have one combo box where i am selecting the database name present in a server.now i want when i am selecting the database it should load all the tables of the database at next combo box.

Please tell me how to do that

Thank you
Posted

Use this query to get respective table of database.

onSelectedIndexChange event of combo run this query and get your output

select table_name from information_schema.tables
where table_catalog = 'DataBase Name' and table_type = 'BASE TABLE'
 
Share this answer
 
v2
Query...
SQL
USE DBNAME; SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'


Pass value of cmbDBList.Text in place of DBNAME in query

Happy Coding!
:)
 
Share this answer
 
Comments
[no name] 5-Apr-13 6:35am    
Thanks..it worked..one more thing..is it possible to take backup of a single table in sql
Aarti Meswania 5-Apr-13 6:38am    
Welcome!
Glad to help you!:)

It depends backup mean which format .bak, excel sheet?
[no name] 5-Apr-13 6:39am    
.bak and .sql i.e script file...both
Aarti Meswania 5-Apr-13 6:40am    
you can create insert statements manually and save file as .sql
[no name] 5-Apr-13 6:43am    
No like programmatic way..how we use to take backup of a database like that if i click backup button it should create the script file to a desired location..
Hello,

Please read[^] this article. Below is an excrept from the same article.
VB
Sub Main()
    Dim connectionString As String = "PUT YOUR CONNECTION STRING HERE"
    Using connection As New SqlConnection(connectionString)
        'Connect to the database then retrieve the schema information.
        connection.Open()
        Dim table As DataTable = connection.GetSchema("Tables")
        // Each row represents a single table
        // For SQL Server each row will have four columns namely table_catalog, table_schema, table_name and table_type
        For Each row As DataRow In table.Rows
            For Each col As DataColumn In table.Columns
                Console.WriteLine("{0} = {1}", col.ColumnName, row(col))
            Next
        Next
    End Using
End Sub

Regards,
 
Share this answer
 

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