How to get Datebase name and tables in sql-server?

  • Thread starter Thread starter ¹ùÑÇ·æ
  • Start date Start date
¹

¹ùÑÇ·æ

In my app,I want to bind Database names with a comboBox in order to
select which database i wanto open .
and I also wanto bind table names with a comboBox, So i can select which
table i wanto use !

how can i code in c# ?

Thanks a lot for any comments !
 
You might try calling the sp_tables and sp_databases stored procedures.
 
You can use the INFORMATION_SCHEMA views in the master database.

to get database:

Select * from INFORMATION_SCHEMA.SCHEMATA

to get tables:

SELect * from INFORMATION_SCHEMA.TABLES where table_catalog = 'Master' or
whatever database you pick.

Hope this helps.
Don
 
Thank you !

i found "select * from sysobjects where xtype='U'" also work well.
but i do not sure if this is correct in coding .
 
I think it is recommended to go off the INFORMATION_SCHEMA views. Lots of
good stuff built in there for you.

Don
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top