我想从 C#中的OleDbDataReader
获取检索到的记录数?
strQuery = "SELECT * FROM Table_Name" ;
dbCommand = new OleDbCommand(strQuery, dbConnection);
dbReader = dbCommand.ExecuteReader();
//Now how to get RowCount from the Table after this.
感谢任何帮助。
感谢。
答案 0 :(得分:7)
更多详情:Get row count by 'ExecuteScalar'
使用ExecuteSclar()
而不是read
功能。
SqlCommand cmd = new SqlCommand("SELECT count(*) FROM " + Table_Name, conn);
try
{
conn.Open();
int total = (Int32)cmd.ExecuteScalar();
}
答案 1 :(得分:1)
您可以将查询更改为:
strQuery = "SELECT count(*) as RowCount, * FROM " + Table_Name;
这将允许您检索行数,如:
dbReader.Read();
var rowCount = (int)dbRead["RowCount"];
答案 2 :(得分:0)
这样做会有,但可能有更好的方法:
int i = 0;
While (dbReader.Read()){
i++;
}