开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜