Get All SQL Database Table Names and Fields Using VB.NET

.Net Framework Logo

Image via Wikipedia

VB.NET Problem

You need to see (write out on your browser’s screen) all of the table names and field names in your back end SQL database and the application is written in .NET, specifically VB.NET on an .aspx page.

VB.NET Resolution

Create a page that uses a connection to your database, the database schema, and the tables it finds to loop through and write the results your browser window.

Background

I came across this need working on a client’s site recently and spent too long searching .NET programming forums for answers. For one reason or another, all of the solutions I encountered didn’t work in my situation. So, here’s another option that will hopefully save you the time.

Copy this file, change the connection string, save it, and upload it to your server.

As always, feel free to contact me with any questions.

Using this code means you agree it is at your own risk, and so forth.

Comments

  1. Hello sir

    very good solution but it gives only master database’ tables if i want to fetch another database then what i have to do

  2. Thanks for your question @param. I’m not sure if I understand you though.

    To get another database’s tables, you would simply change the connection string to that of the other database.

    If you want to get more than one database’s tables at the same time, you could copy the function, rename it, update the second database connection string, and paste it below the first < %showTables%>.

    Or, to make it more user-friendly, you could edit the function, making the connection string a variable and then pass that string into the function like < %showTables(connectionString)%>. Then you could call the showTables function for as many databases as you’d like.

    Is this what you meant?

  3. Deepak Puri says:

    That was very helpful, thanks

  4. Worked perfect. Thank you Aaron.

Speak Your Mind

*