Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting MySQL record count with C#

I would like to know how can I get record count of a query with C#.

Here is the code that I use..

    MySqlDataReader recordset = null;
    query = new MySqlCommand("SELECT * FROM test ORDER BY type_ID ASC", this.conn);
    recordset = query.ExecuteReader();


    while (recordset.Read())
    {
        result.Add(recordset["type_ID"].ToString());

    }
    return result;
like image 876
she hates me Avatar asked May 11 '10 00:05

she hates me


1 Answers

I was using a SELECT COUNT(*) and expected an int to be returned. You may need this to get a usable value:

mysqlint = int.Parse(query.ExecuteScalar().ToString());
like image 142
Trevorm Avatar answered Sep 28 '22 02:09

Trevorm