我只是想检索数据库中表的列名。我编写的SQL查询(在phpMyAdmin中有效)是:
query = "SELECT column_name FROM information_schema.columns WHERE table_schema='hf_framework' AND table_name='elements'";
我的代码如下:
connection = new MySqlConnection(connectionString);
connection.Open();
MySqlCommand cmd = new MySqlCommand(query, connection);
MySqlDataReader dataReader = cmd.ExecuteReader();
while (dataReader.Read()) {
//stuff in there
}
dataReader.Read()总是返回false,我从不进入while循环。
但是,如果我将查询更改为:
query = "SELECT column_name FROM information_schema.columns";
...然后我进入了while循环。我错过了什么?非常感谢。