Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.