Getting List of Tables in Database from ADO - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Getting List of Tables in Database from ADO

kapiloo7kapiloo7 Posts: 45Member
Hi

I need to get list of tables of the database to which I am connecting. How can I achieve this with ADO .NET.

Thanks
Kapil

Comments

  • bradwangbradwang Posts: 197Member
    : Hi
    :
    : I need to get list of tables of the database to which I am
    : connecting. How can I achieve this with ADO .NET.
    :
    : Thanks
    : Kapil


    Hello Kapil, you can use the following code sample:

    string connectionString = "...";
    DataTable tables = new DataTable("Tables");
    using (SqlConnection connection = new SqlConnection(connectionString))
    {
    SqlCommand command = connection.CreateCommand();
    command.CommandText = "select table_name as Name from INFORMATION_SCHEMA.Tables where TABLE_TYPE = 'BASE TABLE'";
    connection.Open();
    tables.Load(command.ExecuteReader( CommandBehavior.CloseConnection));
    }


    Hope it helps. :)



    Brad Wang
    .NET Freelancer from China
Sign In or Register to comment.