从OracleDataReader行数行数、OracleDataReader

2023-09-06 07:53:15 作者:果果需要你

任何一个可以告诉我如何找到行数由 OracleDataReader 在.NET 2.0?

解决方案   

这是 OracleDataReader 对象重新presents   一个只进,只读,内存   结果集。不同于数据集中,    OracleDataReader 对象入住   连接并获取一行一   时间。

所以,它不知道有多少行会。如果您使用的数据 适配器,那么你就可以得到一个行数,因为它取了 行。

在你的情况,你必须获取所有行(如果你需要获取的数据只),以获取该行数:

  OracleDataReader读卡器= cmd.ExecuteReader();
INT rowCount时= 0;
而(reader.Read())
{
    //此处是您的逻辑
    rowCount等++;
}
 
在ORACLE中怎么添加查询结果的显示行数

不过,如果你并不需要这些数据,这将是更好地改写存储过程/查询返回的行数显式

Can any one tell me how to find row count from OracleDataReader in .net 2.0?

解决方案

An OracleDataReaderobject represents a forward-only, read-only, in-memory result set. Unlike the DataSet, the OracleDataReaderobject stays connected and fetches one row at a time.

So, it does not know how many rows there will be. If you use the data adapter, then you will be able to get a row count since it fetches the rows.

In your case you have to fetch all the rows (if you need to fetch the data only) to get the row count:

OracleDataReader reader = cmd.ExecuteReader();
int rowCount = 0;
while (reader.Read())
{
    // your logic here
    rowCount++;
}

But if you don't need that data, it would be better to reformulate your stored procedure/query to return row count explicitly.