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