count of records in recordset

  • Thread starter Thread starter D.
  • Start date Start date
D

D.

Hi,

I need to know how many records i get from a sql statement.
I use this and it works (amount of records = rec), but is there no better
way to to that?
Thanks
Dominique

...
comd = New System.Data.OleDb.OleDbCommand(sql, oConnection)
dtreader = comd.ExecuteReader
If dtreader.HasRows Then
While dtreader.Read()
rec = rec + 1
End While
End If
dtreader.Close()
 
2 options:

-Do a count (*) query. If you need the data and the count, this would mean
you execute the query a second time, essentially.
-Use a datatable instead of a datareader.

Additionally, this question has been asked hundreds of times. If you do a
google search you will find similar responses.
 
Thanks

Marina Levit said:
2 options:

-Do a count (*) query. If you need the data and the count, this would mean
you execute the query a second time, essentially.
-Use a datatable instead of a datareader.

Additionally, this question has been asked hundreds of times. If you do a
google search you will find similar responses.
 
Back
Top