我试过了:
MySqlConnection con = new MySqlConnection(...);
con.Open();
MySqlCommand cmd = new MySqlCommand();
cmd.Connection = con;
cmd.CommandText = "SELECT * FROM questions;";
MySqlDataReader reader = cmd.ExecuteReader();
reader.Read();
int i = 0, len = reader.FieldCount;
while (i < len)
{
Response.Write(reader.GetString(i));
i++;
}
仅返回表中的第一个值。如何得到所有? 提前谢谢
答案 0 :(得分:5)
您必须致电reader.Read()
,直到它返回false
。
我也冒昧地将你的内循环转换为for
循环。
while (reader.Read())
{
for (int i = 0; i < reader.FieldCount; i++)
{
Response.Write(reader.GetString(i));
}
}
阅读本文以阅读IDataReader
:http://msdn.microsoft.com/en-us/library/system.data.idatareader.read.aspx