DataReader + Get numbers of rows + retriev string from ranome row

Andi03

Active member
Joined
Sep 5, 2003
Messages
43
Hi.

1.
How can I get the total amount of rows in a DataReader? I know I can make a "Do Loop" like this:

Code:
Do While DR.Read()
Count = Count + 1
Loop

But wont it slow my page down let say if I have 1000+ post in it? Isnt there a way like a propery I can get the info from?

2.
If I know I want to retriev the info in a filed on row 33. Can I get that info direct or do I have to do like this or something like this:

Code:
PostNumber = 33
For i = 1 to PostNumber
DR.Read()
If i = PostNumber Then Response.Write(DR("field"))
Next

But still how efective is this when I have a DB with 1000+ post in it? Isent there a easier way?

//Andi
 
Since DataReader reads records one at a time, I dont believe you can. Youd have to use DataAdapter and fill DataSets (or DataTables) if you want to get information on whats retrieved as a whole.

Instead of looping, you can always use a SQL command to return the number of records (use ExecuteScalar from the Command object)

SELECT COUNT(*) FROM TABLE WHERE COLUMN=VALUE
 
Back
Top