ASP 101 - Active Server Pages 101 - Web03
The Place ASP Developers Go!

Windows Technology Windows Technology
15 Seconds
ASP 101
ASP Wire
VB Forums
VB Wire
internet.commerce internet.commerce
Partners & Affiliates
ASP 101 is an site
ASP 101 is an site
Internet News
Small Business
Personal Technology

Corporate Info
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash

 Top ASP 101 Stories Top ASP 101 Stories
What is ASP?
VBScript Classes: Part 1 of N
Migrating to ASP.NET

Connection Pooling lightens the load
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates

Quick Tips

How To List The Tables In A Database

While developers are usually interested in accessing the data contained within a database's tables, occasionally you need to know something about the tables themselves. It's at these times when this quick tip might come in handy.

The magic behind this tip is the GetSchema method of the connection object. It'll give you all sorts of information about the database to which you are currently connected. I'm not going to go into it in depth because that would turn this quick tip into a long article, but I will give you a sample code snippet which will list all the tables in the current database.

<%@ Page Language="VB" %>
<script runat="server">

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim cnnTables As New System.Data.SqlClient.SqlConnection
        cnnTables.ConnectionString = "Data Source=localhost;Initial Catalog=DB_NAME;User ID=USER;Password=PASS;"


        gridTables.DataSource = cnnTables.GetSchema("Tables")

    End Sub

    <title>List Tables In Database</title>
<form id="myForm" runat="server">

<asp:GridView ID="gridTables" runat="server" />


In order to get information about your database you'll obviously need to use your own connection string, but aside from that the code is pretty straight-forward. If you want to learn more about the GetSchema method and filtering your results via restrictions, you're probably best off heading straight to the source and checking out the documentation from Microsoft:

Previous      Show All Tips      Next

If you have a tip you would like to submit, please send it to:

Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback
The Network for Technology Professionals



Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers