Record count in asp using vb.net

S

Scott M.

A DataReader has exactly 1 record in it at any one time and therefore does
not support a RecordCount like classic ADO did.

You could do this though...

Dim i as Integer
Dim ReaderValue as String
Do While objDataReader.Read()
i += 1
ReaderValue = "Municipio=" & objDataReader("Municipio") & "&vr=" &
objDataReader("vr")
Loop

'At this point, i is equal to the amount of records in the DataReader
'and ReaderValue is equal to the name/value pairs in the reader

On a side note, in ASP.NET, you really don't need "Response.Write()"
statements anymore (allthough they still work). Just set up a Web Form
Label control and set its text property:

lblData.Text = ReaderValue

Scott M.
 
R

RAW

I am triyng to display the total of my records on my page using
RecordCounter as I used to in asp

thid sombody can give me an example


asp using vb.net


DIM mySqlStatment AS STRING = "SELECT * FROM properties WHERE Municipio = '"
& Replace(Municipio_Str, "'", "''") & "' AND '" & Replace(vr_Str,"'","''")
& "' OR '" & Replace(MLS_Int,"'", "''") & "'"

DIM objConnection AS NEW OledbConnection(strConnection)
DIM objCommand AS NEW oledbCommand(mySqlStatment, objConnection)
DIM objDataReader AS oledbDataReader

try
objConnection.open()
objDataReader = objCommand.ExecuteReader()

DO WHILE objDataReader.Read()= true

Response.write("Municipio")
Response.write("=")
Response.write(objDataReader("Municipio"))
Response.write("&")
Response.write("vr")
Response.write("=")
Response.write(objDataReader("vr"))
Response.write("&")
 
R

RAW

thanks for the tip

Scott M. said:
A DataReader has exactly 1 record in it at any one time and therefore does
not support a RecordCount like classic ADO did.

You could do this though...

Dim i as Integer
Dim ReaderValue as String
Do While objDataReader.Read()
i += 1
ReaderValue = "Municipio=" & objDataReader("Municipio") & "&vr=" &
objDataReader("vr")
Loop

'At this point, i is equal to the amount of records in the DataReader
'and ReaderValue is equal to the name/value pairs in the reader

On a side note, in ASP.NET, you really don't need "Response.Write()"
statements anymore (allthough they still work). Just set up a Web Form
Label control and set its text property:

lblData.Text = ReaderValue

Scott M.


=
 
M

Mark

Hi, the DataView object of ADO.net has a count property what will return the
number of rows in the DataSet. Overhead is more than just using loop like
Scott.M mentioned. You could always use SQL to do the count for you and then
query this via the datareader...

SELECT COUNT(EmployeeID) AS EmployeeNumber FROM Employees

Response.write("Number of employees is : " & oDR("EmployeeNumber"))

HTH
Cheers
mark
 
Joined
Mar 18, 2009
Messages
5
Reaction score
0
I may have misunderstood what you're trying to do but couldn't you simply get a record count from the SQL SelectCommand in your data source - SELECT COUNT(*) AS RecordCount. You could then bind this to a control using <%#Eval("RecordCount")%> in the template.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top