How to find Number of Rows in DataReader

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using DataReader to populate my data. I want to find the number of rows
in the DataReader. How to go about doing this. Is there any property or
method available. I know that, it is a forward only read only cursor. But, I
am a situation to find the number of rows.
Please give me few tips..
 
You can't as this is a forward only cursor, there is no way to know the
number of rows before reading them all.

You could use a DataTable or perform a SQL count request before reading the
rows... Do you really rad this number before reading the rows ?

The whole picture may help to raise better suggestions.

Patrice
 
Patrice,

What is in your opinion wrong with the count as you sugested, this is mostly
used to let a progressbar go?

To give the code to Perin
\\\
dim cmd as New SqlCommand("select count(*) from tbl", conn)
count As Integer = CInt(cmd.ExecuteScalar())
///

Cor
 
Ok looks good.

Most often I prefer to have the whole picture as it may raise better
suggestions.

Recently I came accross someone who wanted to use an include file (actually
it was because he didn't know how to get the current HTTP request in a user
control or a class). Another one wants to run an app every 10 seconds.
Actually it looks like to check a file and a file watcher could perhaps does
the job etc...

Patrice

--
 
Hi Cor,

The problem is that you have to execute the select twice to get all the
data - once for count and once for retrieving data.
This might be a problem if select takes long time to execute, plus it might
be unreliable if somebody modifes the data of result between two selects.
It is far better to display a infinite kind of progress bar and refresh the
number of items retrieved from time to time.
 
Hi Miha,

Did you somehow read the language vb newsgroup and all my messages which are
the same as you write now about that. (However I wrote that as well in this
newsgroup)

I always tell that there is a special avi in the vsnet toolbox for that.

Do you remember that long try from Bernie, where I gave up telling that.

It seems for me that some people find the progressbar more important than
for the user in time loading. (However there is for me the exception in case
of offline creating a pda dataset).

Therefore I am glad that I succeeded and you are telling it in my opinion it
in almost the same way now

:-))

Cor
 
Back
Top