I have an ASP.NET application in which I need to connect to a specific SQL Server database and then list all of the tables contained within that database.
How can I accomplish this?
Printable View
I have an ASP.NET application in which I need to connect to a specific SQL Server database and then list all of the tables contained within that database.
How can I accomplish this?
Are you asking how to get the list of table names from sql server or how to show them on a web page (or both)
If its the former then some options
1) Every SQL Server database has system Views that you can use to get schema information. Just run a query on the view. Something like
2) Use ADOX.Code:Select TableName From Information_Schema.Tables
Where Table_Type = 'Base Table'
3) Access the sql server system tables directly.
Thanks.
or
Code:SELECT * FROM sysobjects WHERE xtype = 'U'
Which is basically what the Information_Schema.TablesQuote:
FROM sysobjects WHERE xtype = 'U'
View executes.