Get the number of Rows returned by a OleDbDataReader ASP.NET (VB)
After connecti开发者_JS百科ng to a database using DataReader
, how can I count the number of rows
?
Thanks.
Data readers are forward only so they don't have the count when first filled. You can do several things to address this:
- Run a separate command to get the count OR using NextResult to help instead of a totally separate command).
- Loop through the results and count the records
- Use a DataSet
Here's an example of #1:
Without NextResult: http://www.devx.com/vb2themax/Tip/18807
With NextResult (Doesn't return record count but gives you idea of how to use NextResult): http://bytes.com/topic/asp-net/answers/295793-datareader-nextresults-question
Here's an example of #2: http://support.microsoft.com/kb/308050
Only by repeatedly calling Read()
.
A DataReader
is a forward-only view of a resultset and cannot get a count.
精彩评论