使用C#获取MySQL记录计数 [英] Getting MySQL record count with C#

查看:936
本文介绍了使用C#获取MySQL记录计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何使用C#获取查询的记录数.

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

这是我使用的代码.

    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;

推荐答案

我正在使用SELECT COUNT(*),并且期望返回int.您可能需要使用它来获得可用的值:

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());

这篇关于使用C#获取MySQL记录计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆