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 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
 
Back
Top