Datareader record count?

  • Thread starter Thread starter mikeb
  • Start date Start date
M

mikeb

After you load a datareader, how can you find out how many records are
loaded?

Dim cmd as New SqlServerCe.SqlCeCommand(Sql, Conn)
dr = cmd.ExecuteReader()

ie:
RecCount = dr.recordcount 'how do I get the count of records loaded?
 
I looked at that, but it says records changed, inserted or deleted. If its
what ever is loaded into the reader - then where would the "changed,
inserted or deleted" come in to play??
 
Right. Never mind that. I think the only way to find the amount of records
will be to keep reading from DataReader until it's done. That's because it
is sequential reader.
As an alternative, you could run the same select statement only with "select
count(*) from ... " and use Command.ExecuteScalar to get the number orf
records
 
mikeb,

ExecuteReader() doesn't get any rows. You have to put the SqlDataReader
returned by ExecuteReader in a loop as in reader.Read () to get rows, so add
a counter to the loop.

SqlDataReader does have a HasRows property though, but I haven't found a use
for it yet.

Graham
 
Back
Top