ExecuteScalar 函数功能

来源:互联网 发布:海康威视网络容错多址 编辑:程序博客网 时间:2024/05/16 09:31

OleDbCommand.ExecuteScalar Method  

MSDN 资料 

Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.

Namespace: System.Data.OleDb
Assembly: System.Data (in system.data.dll)

用处: 查询数据库总记录数

        string querystr = "select count(*) From ConanMsg";
        OleDbCommand mycommand;
        mycommand 
= new OleDbCommand(querystr, myconn);
        
int count = (int)mycommand.ExecuteScalar();

count里保存的就是总记录数.

原创粉丝点击