Rich wrote:[color=blue]
> Is there any builtin functionality to the SqlDataReader for getting a row
> count of records retrieved? Rather than Do While rdr.Read: i+=1: Loop?[/color]
No, since the datareader only fetches rows as you ask for them
(rdr.Read) it does not know how many there will be. If you use the data
adapter, then you will be able to get a row count since it fetches the
rows. Otherswise, make to calls, on to get the rowcount and one to get
the data.
Hello Rich
I donot think there is a property that can give you the row count right away
just like the record count property of ADODB.Recordset
Probably, You can load the data into a dataset and use datarow collection to
get the row count.
Let me know if you find a better solution
Thanks
Deepak
"Rich" wrote:
[color=blue]
> Is there any builtin functionality to the SqlDataReader for getting a row
> count of records retrieved? Rather than Do While rdr.Read: i+=1: Loop?[/color]
Thanks all for your replies. Basically, I have a sql table that contains
columns of column names for other tables. Col1 may contain 90 rows where
each cell contains column names for tbl1, Col2 contains 40 rows of not null
data for the columns in tbl2, ...
I am using a datareader to read the not null values in each column
individually, and I loop through the datareader to add sqlInsertComman d
Params (for my Insert SP in sql server which has the same number of params).
So I am stuck with using
i += 1 '--i is the column ordincal for tlb1 and tbl2 and the row in the
columnNames
'--table
'--rdr reads the rows in the ColumnNames table
While rdr.Read
str1 = rdr.GetString(0 )
'--this is a Text field for tbl1 and tbl2
If ((stp = "cd" Or stp = "qa") And i = 2) Or (stp = "qa" And i = 8) Then
cmdNcalInsert.P arameters.Add(s tr1, SqlDbType.NText , 16,
str1.Substring( 1, str1.Length - 1))
ElseIf str1 = "@RowNum" Then
cmdNcalInsert.P arameters.Add(s tr1, SqlDbType.Int, 4, str1.Substring( 1,
str1.Length - 1))
Else
cmdNcalInsert.P arameters.Add(s tr1, SqlDbType.NVarC har, 20,
str1.Substring( 1, str1.Length - 1))
End If
i += 1
End While
"Rich" wrote:
[color=blue]
> Is there any builtin functionality to the SqlDataReader for getting a row
> count of records retrieved? Rather than Do While rdr.Read: i+=1: Loop?[/color]
This kind of procedures you can nicely do with a progressbar. And of couse
do you than have to set the steps of the progressbar yourself. (something
you do now)
If finding out the number of rows is really important
executenonquery will return the number of rows affected. You still will
have use executereader to get a datareader. Running the query twice will
impact performance.
Ken
---------------
"Rich" wrote:
[color=blue]
> Is there any builtin functionality to the SqlDataReader for getting a row
> count of records retrieved? Rather than Do While rdr.Read: i+=1: Loop?[/color]
Basically, I have a table in sql server that has 4 columns/fields. Each
column represents a different sql server table. I load parameter names in
each column
Each table has different fields and different number of fields. I have 4
separate Insert Into SPs for each table that take the respective parameters.
The params are averageing from 30 params for one table to 180 params for
another table. Too many params for an array of params (already tried - works
but way too messy). So I decided to list my params for each table in a
Params Table. I use the datareader to read each column for each table
strSql = "Select col1 From tblParams Where col1 Is Not Null"
for tbl1 for example. I loop through the data reader and load up my params.
I can't even remember why I needed the count of rows. But I do need to know
what row I am on because for col1 row3 the param has to be ntext, the rest of
the rows are nvarchar(100), lastfld is int, for example.
Rich
"Ken Tucker [MVP]" wrote:
[color=blue]
> Hi,
>
> If finding out the number of rows is really important
> executenonquery will return the number of rows affected. You still will
> have use executereader to get a datareader. Running the query twice will
> impact performance.
>
> Ken
> ---------------
>
> "Rich" wrote:
>[color=green]
> > Is there any builtin functionality to the SqlDataReader for getting a row
> > count of records retrieved? Rather than Do While rdr.Read: i+=1: Loop?[/color][/color]
"Cor Ligthert [MVP]" wrote:
[color=blue]
> Rich,
>
> This kind of procedures you can nicely do with a progressbar. And of couse
> do you than have to set the steps of the progressbar yourself. (something
> you do now)
>
> See this sample on our website
> http://www.windowsformsdatagridhelp....6-fc0d5c470f53
>
> I hope this gives an idea.
>
> Cor
>
>
>[/color]
Comment