|
 |
aspx thread: Best way to count rows in datareader object
Message #1 by "Greg Quinn" <greg@i...> on Mon, 21 Jan 2002 15:00:10 -0800
|
|
Hi,
This is the only way I have discovered to get the number of rows in a
DataReader object, can anyone think of a better way.
If someone could also post code on how I can access the count property
returned by a SQL statement, that would also help..
Dim numRowsInQuery as Integer = 0
Do While objDataReader.Read()
stringResult += "<tr bgcolor = '#0589BC'><td>" & objDataReader("ID") &
"</td><td> " _
& objDataReader("CompanyName") & "</td><td> " _
& objDataReader("ContactNumber") & "</td></tr>"
numRowsInQuery += 1
Loop
Message #2 by "Greg Quinn" <greg@i...> on Mon, 21 Jan 2002 15:48:12 -0800
|
|
Okay, I worked it out, here is the code that does it...
<%@ Import NameSpace = "System.Data" %>
<%@ Import NameSpace = "System.Data.OleDB" %>
<script language = "vb" runat = "server">
Sub Page_Load()
Dim myConnection as New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Projects\OfficiumBeta\database\officiumbeta.mdb;")
Const strSQL as String = "Select Count(1) From CallCustomers"
Dim objCommand as New OleDBCommand(strSQL, myConnection)
myConnection.Open
Dim numRowsInQuery as Integer
numRowsInQuery = objCommand.ExecuteScalar()
numRows.innerHTML = numRowsInQuery
myConnection.Close()
End Sub
</script>
<html>
<body>
<div id = "numRows" runat = "server" />
</body>
</html>
|
|
 |