简体   繁体   中英

How to obtain list of tables names from a MySQL database in a C#?

如何从C#中的MySQL数据库获取表名列表?

see this link, its explain from the beginning of connect

http://www.geekpedia.com/tutorial139_Connecting-to-MySQL-with-Csharp-and-ODBC.html

u need to run "show tables"

private void btnListTables_Click(object sender, EventArgs e)

{

      if (OdbcCon.State == ConnectionState.Open)

      {

            // Execute the SHOW TABLES query on the MySQL database

            OdbcCom = new System.Data.Odbc.OdbcCommand("SHOW TABLES", OdbcCon);

            OdbcDR = OdbcCom.ExecuteReader();

            txtLog.AppendText("Tables inside " + txtDatabase.Text + ":\r\n");

            // Loop through the list of tables and display each one

            while (OdbcDR.Read())

            {

                  txtLog.AppendText(">> " + OdbcDR[0] + "\r\n");

            }

      }

}

Is it useful? I think you may query MySql db from C# normally with this syntax, then consume the results.

Got the solution:

Here it is

SELECT TABLE_NAME FROM Information_Schema.Tables where Table_Type = 'BASE TABLE'

Hope this helps everyone looking out for an answer. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM