[英]How to obtain list of tables names from a MySQL database in a C#?
如何从C#中的MySQL数据库获取表名列表?
看到此链接,从连接开始对其进行说明
http://www.geekpedia.com/tutorial139_Connecting-to-MySQL-with-Csharp-and-ODBC.html
你需要运行"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");
}
}
}
它有用吗? 我认为您通常可以使用这种语法从C#查询MySql数据库,然后使用结果。
得到了解决方案:
这里是
SELECT TABLE_NAME FROM Information_Schema.Tables where Table_Type = 'BASE TABLE'
希望这可以帮助所有人寻找答案。 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.