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; 回答1: 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()