You must Sign In to post a response.
  • Category: ASP.NET

    How to list tables of sql database

    hi,
    I am having a problem with getting list of all tables from available database.
    I have created sql datase and dont know how to get list of all tables from that database. i have tried following code.dont know whether it is right or wrong.

    SqlConnection c = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\user\Documents\Visual Studio 2008\Projects\WebApplication3\WebApplication3\App_Data\Databas1.mdf;Integrated Security=True;User Instance=True");
    DataTable dt = new DataTable();
    c.Open();
    dt = c.GetSchema();
    c.Close();
    GridView d = new GridView();
    d.DataSource = dt;
    d.DataBind();
    form1.Controls.Add(d);
  • #582694
    Hi Mai,

    You can get the list of tables from a database using following query,

    SELECT *
    FROM sys.Tables

    Use this query to get the list of tables.

    Regards,
    V.M. Damodharan
    "Your talent will be worthless, when you have fear and tension."

  • #582695
    Hi,

    SELECT * FROM sys.Tables

    Thanks!!!
    Shatrughna
    http://shatrugna.blogspot.com

  • #582701
    hi you can try sql query for that like this

    select * from sysobjects where xtype='u'order by name


    hope this will help you

  • #582763
    hi try this codings

    SELECT * FROM information_schema.tables







    Thanks and REgards

  • #582774

    SELECT * FROM sys.Tables

    Which will list all the tables in the Database.

    All is well.
    Thanks,
    Dharma
    Editor,Mentor,MVM
    Try and fail but don't fail and try

  • #582783
    hi all,
    thnx for ur responces..but i want to display list of tables and how i will get those using above..becouse i will get result in dataset or datatable..then how should i get name of table from it.explain in detail.

  • #582989
    select * from tab;

  • #582990
    Hi Mai,

    Just retrieve table name only in your dataset. After retrieving the result using for loop you can get each table names.

    SELECT Name FROM sys.Tables

    Regards,
    V.M. Damodharan
    "Your talent will be worthless, when you have fear and tension."


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.