Record count in asp using vb.net

  • Thread starter Thread starter Scott M.
  • Start date Start date
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.
 
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("&")
 
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.


=
 
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
 
Back
Top