当我们使用c#.net点击按钮时,你能告诉我如何从mysql服务器数据库中检索表名。 例如,当我点击按钮获取表名时,我的数据库中有表名注册,只显示一个表名。 我试过以下代码
DataTable dt = new DataTable();
TextBox1.Text = dt.TableName[0].ToString();

答案 0 :(得分:0)
这就是你要找的东西吗?
using MySql.Data.MySqlClient;
string myConnectionString = "SERVER=localhost;" +
"DATABASE=mydatabase;" +
"UID=user;" +
"PASSWORD=mypassword;";
MySqlConnection connection = new MySqlConnection(myConnectionString);
MySqlCommand command = connection.CreateCommand();
command.CommandText = "SHOW TABLES;";
MySqlDataReader Reader;
connection.Open();
Reader = command.ExecuteReader();
while (Reader.Read())
{
string row = "";
for (int i = 0; i < Reader.FieldCount; i++)
row += Reader.GetValue(i).ToString() + ", ";
Console.WriteLine(row);
}
connection.Close();