how get all records on database using mysql?
I tried this:
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++;
}
returns only the first values from table. how get all? thanks in advance开发者_StackOverflow
You have to call reader.Read()
until it returns false
.
I've also taken the liberty of converting your inner loop to a for
loop.
while (reader.Read())
{
for (int i = 0; i < reader.FieldCount; i++)
{
Response.Write(reader.GetString(i));
}
}
Read this to read up on the IDataReader
: http://msdn.microsoft.com/en-us/library/system.data.idatareader.read.aspx
精彩评论