Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. display the list of tables in a mysql database

display the list of tables in a mysql database

Scheduled Pinned Locked Moved C#
databasemysqltutorial
11 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M MemberDotNetting

    how to display the list of tables in a mysql database, I have at my application module that requires selection of the database and selection of the table that will display its contents

    E Offline
    E Offline
    egenis
    wrote on last edited by
    #2

    You need to execute a query against the db. Something like

    SHOW [FULL] TABLES [{FROM | IN} db_name]
    [LIKE 'pattern' | WHERE expr]

    Go look at http://dev.mysql.com/doc/[^] to find the correct syntax for the version you are working on. Maybe execute it as a stored proc and return it to your application.

    1 Reply Last reply
    0
    • M MemberDotNetting

      how to display the list of tables in a mysql database, I have at my application module that requires selection of the database and selection of the table that will display its contents

      W Offline
      W Offline
      Wayne Gaylard
      wrote on last edited by
      #3

      You need to query the Information_Schema database, something like this:-

      SELECT Table_Name FROM Information_Schema.Tables WHERE Table_Type = 'BASE TABLE' AND Table_Schema = 'yourSchema'

      This will give you the names of all the tables in your schema.

      When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman

      1 Reply Last reply
      0
      • M MemberDotNetting

        how to display the list of tables in a mysql database, I have at my application module that requires selection of the database and selection of the table that will display its contents

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #4

        You don't need any SQL:

        public override List GetTableNames() {
        using (OleDbConnection con=new OleDbConnection(connectionString)) {
        con.Open();
        DataTable dt=con.GetSchema("Tables");
        List tableNames=new List();
        foreach (DataRow row in dt.Rows) {
        string tableName=(string)row["TABLE_NAME"];
        tableNames.Add(tableName);
        }
        return tableNames;
        }
        }

        :)

        Luc Pattyn [My Articles] Nil Volentibus Arduum

        M P 3 Replies Last reply
        0
        • L Luc Pattyn

          You don't need any SQL:

          public override List GetTableNames() {
          using (OleDbConnection con=new OleDbConnection(connectionString)) {
          con.Open();
          DataTable dt=con.GetSchema("Tables");
          List tableNames=new List();
          foreach (DataRow row in dt.Rows) {
          string tableName=(string)row["TABLE_NAME"];
          tableNames.Add(tableName);
          }
          return tableNames;
          }
          }

          :)

          Luc Pattyn [My Articles] Nil Volentibus Arduum

          M Offline
          M Offline
          MemberDotNetting
          wrote on last edited by
          #5

          thank you :)

          1 Reply Last reply
          0
          • L Luc Pattyn

            You don't need any SQL:

            public override List GetTableNames() {
            using (OleDbConnection con=new OleDbConnection(connectionString)) {
            con.Open();
            DataTable dt=con.GetSchema("Tables");
            List tableNames=new List();
            foreach (DataRow row in dt.Rows) {
            string tableName=(string)row["TABLE_NAME"];
            tableNames.Add(tableName);
            }
            return tableNames;
            }
            }

            :)

            Luc Pattyn [My Articles] Nil Volentibus Arduum

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #6

            I've never tried to access MySql with OleDb; I've always used the MySql .net connector. On a MySql database I access at work that doesn't work :sigh: -- it seems it may be an older version of MySql.

            T M L 3 Replies Last reply
            0
            • P PIEBALDconsult

              I've never tried to access MySql with OleDb; I've always used the MySql .net connector. On a MySql database I access at work that doesn't work :sigh: -- it seems it may be an older version of MySql.

              T Offline
              T Offline
              TenmanS14
              wrote on last edited by
              #7

              PMSL... or just SHOW DATABASES; oops... or indeed SHOW TABLES; edit... why did I think that said show tables the first time I edited, then edit it again to be incorrect to show databases... my excuse is that it was Wednesday...

              1 Reply Last reply
              0
              • P PIEBALDconsult

                I've never tried to access MySql with OleDb; I've always used the MySql .net connector. On a MySql database I access at work that doesn't work :sigh: -- it seems it may be an older version of MySql.

                M Offline
                M Offline
                MemberDotNetting
                wrote on last edited by
                #8

                yes i chenged OLEDB with Mysql and it work

                1 Reply Last reply
                0
                • P PIEBALDconsult

                  I've never tried to access MySql with OleDb; I've always used the MySql .net connector. On a MySql database I access at work that doesn't work :sigh: -- it seems it may be an older version of MySql.

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #9

                  My mistake. That was a code snippet I once used on Access. I trust the same approach works just fine on MySQL, mutatis mutandis. :-O

                  Luc Pattyn [My Articles] Nil Volentibus Arduum

                  P 1 Reply Last reply
                  0
                  • L Luc Pattyn

                    My mistake. That was a code snippet I once used on Access. I trust the same approach works just fine on MySQL, mutatis mutandis. :-O

                    Luc Pattyn [My Articles] Nil Volentibus Arduum

                    P Offline
                    P Offline
                    PIEBALDconsult
                    wrote on last edited by
                    #10

                    My problem was my mistake as well... the userID I was given only has access to views, so of course they didn't show up when I asked for tables. :doh:

                    1 Reply Last reply
                    0
                    • L Luc Pattyn

                      You don't need any SQL:

                      public override List GetTableNames() {
                      using (OleDbConnection con=new OleDbConnection(connectionString)) {
                      con.Open();
                      DataTable dt=con.GetSchema("Tables");
                      List tableNames=new List();
                      foreach (DataRow row in dt.Rows) {
                      string tableName=(string)row["TABLE_NAME"];
                      tableNames.Add(tableName);
                      }
                      return tableNames;
                      }
                      }

                      :)

                      Luc Pattyn [My Articles] Nil Volentibus Arduum

                      M Offline
                      M Offline
                      MemberDotNetting
                      wrote on last edited by
                      #11

                      can I use the same function to show the list of databases names?

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups