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..
--
Perin

Re: How to find Number of Rows in DataReader by Patrice

Patrice
Tue Dec 07 04:43:45 CST 2004

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

--

"Perin" <jacksonronaldperin@hotmail.com> a écrit dans le message de
news:FE00B844-A378-41E5-8583-EFF6194D3944@microsoft.com...
> 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..
> --
> Perin



Re: How to find Number of Rows in DataReader by Cor

Cor
Tue Dec 07 04:59:07 CST 2004

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

"Patrice" <nobody@nowhere.com>

> 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
>
> --
>
> "Perin" <jacksonronaldperin@hotmail.com> a écrit dans le message de
> news:FE00B844-A378-41E5-8583-EFF6194D3944@microsoft.com...
>> 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..
>> --
>> Perin
>
>



Re: How to find Number of Rows in DataReader by Patrice

Patrice
Tue Dec 07 05:13:51 CST 2004

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

--

"Cor Ligthert" <notmyfirstname@planet.nl> a écrit dans le message de
news:OsrLMuE3EHA.3616@TK2MSFTNGP11.phx.gbl...
> 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
>
> "Patrice" <nobody@nowhere.com>
>
> > 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
> >
> > --
> >
> > "Perin" <jacksonronaldperin@hotmail.com> a écrit dans le message de
> > news:FE00B844-A378-41E5-8583-EFF6194D3944@microsoft.com...
> >> 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..
> >> --
> >> Perin
> >
> >
>
>



Re: How to find Number of Rows in DataReader by Miha

Miha
Tue Dec 07 05:52:56 CST 2004

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.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
SLODUG - Slovene Developer Users Group
www.rthand.com

"Cor Ligthert" <notmyfirstname@planet.nl> wrote in message
news:OsrLMuE3EHA.3616@TK2MSFTNGP11.phx.gbl...
> 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
>
> "Patrice" <nobody@nowhere.com>
>
>> 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
>>
>> --
>>
>> "Perin" <jacksonronaldperin@hotmail.com> a écrit dans le message de
>> news:FE00B844-A378-41E5-8583-EFF6194D3944@microsoft.com...
>>> 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..
>>> --
>>> Perin
>>
>>
>
>



Re: How to find Number of Rows in DataReader by Cor

Cor
Tue Dec 07 06:12:05 CST 2004

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

>
> 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.
>