Reputation: 97
I know similar questions have been asked many times. But its not working for me. I am working on windows form application. I have placed a list box in one of the forms and want it to display the names of the tables stored in the database. What query should I write to access the tables ?
USE db_name
SELECT * FROM sys.Tables
My database name is dbSave.mdf
but it doesnt work if I put this as db_name in the above query
Please help...
Upvotes: 0
Views: 688
Reputation: 139
I think your Query is fine to retrieve table list from a Database
SELECT * FROM sys.Tables
No need to use Use DB because your application connection string already connected with that database . Once that is another DB please create new connection string for that database .
And also verify that your User have enough right in that working database.
Upvotes: 0
Reputation: 74
SELECT * FROM sys.objects
WHERE Type_desc='USER_TABLE'
I hope this will help you :)
Also yo can create filter on schema or databse level
Upvotes: 0
Reputation: 1299
This one works for me:
SELECT * FROM information_schema.tables
I found it here.
Upvotes: 1
Reputation: 4006
What you're looking for is different from databse to database. Your best bet is to use some sort of abstract api. I'm not familiar with .NET's data access but in java's libraries you use "MetaData" objects to do it.
Upvotes: 0