Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have two combobox, in one combobox i am getting all databases name of sqlserver now when i select any database from combobox i want to show all tables related to that database in second combobox.

i am using this query but it is not working

"SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA ='" + cmbdatabase.Text.Trim() + "'"

please help me.....
Posted

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 teh connection:
SQL
USE yourDBName; SELECT name FROM sys.Tables
 
Share this answer
 
Try the following -
"USE " + cmbdatabase.Text.Trim() + "; SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES"<br />
 
Share this answer
 
Comments
Member 11014751 15-Aug-14 8:05am    
It is giving error
" Database 'System' does not exist. Make sure that the name is entered correctly. "
Member 11014751 15-Aug-14 8:36am    
Please Help i want to submit my assignment today. :(
Abhinav S 15-Aug-14 9:44am    
What is your first query?
Member 11014751 16-Aug-14 0:59am    
What do you means by first query?
Member 11014751 16-Aug-14 1:12am    
Its Done :):):):):) Thanks Alot to all

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