[pic]

[ Home ] [ Discuss ] [ Documentation ]
Search:

 

 
ASP Source Code:
<%@ Language = VBScript %>
<%option explicit%>
<!--#include file="adovbs.inc"-->
<html>

<head>
<title>SQL Example</title>
<link rel="stylesheet" href="/core.css">
</head>

<body>
<!--#include virtual="header.html"-->

<center><h1>Determining the number of records in a recordset</h1></center>

<p>
This demonstrates the use of recordcount to determine the number of records in a 
recordset.  The 
<a href="source.asp?file=<%= right(Request.ServerVariables("PATH_INFO"), len(Request.ServerVariables("PATH_INFO"))-instrrev(Request.ServerVariables("PATH_INFO"), "/")) %>">source</a>
is also available.
</p>

<p>
<%
dim count, oConn, oRs, offset, i

SET oConn = Server.CreateObject("ADODB.Connection")

if oConn = null then
  abort()
end if

oConn.Open "DSN=qcd;UID=qsql;Password=pa$$w0rd;"
if oConn = null then
  abort()
end if

set oRs = Server.CreateObject("ADODB.recordset")
oRs.CursorLocation = adUseClient  'neccessary for recordcount to work
oRs.open "SELECT * FROM EMPLOYEE_MASTER", oConn
response.write "[RecordCount: " & oRs.RecordCount & "]<br><br/>" & vbCrLf

' Move to the last 10 records
offset = 0
response.write "Starting at record " & offset+1 & "<br><br/>" & vbCrLf
oRs.Move offset

' Print out the records
WHILE NOT oRs.EOF and i<10
  response.write oRs.Fields("FIRST_NAME").Value & " "  & _
    oRs.Fields("LAST_NAME").Value & "<br/>" & vbCrLf
  oRs.MoveNext
  i = i + 1
WEND
%>
</p>

<!--#include virtual="footer.html"-->
</body>

</html>
© 1999-2019, Qantel Technologies, Inc.