Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a RecordSet twice 1

Status
Not open for further replies.

jon24422531

Technical User
Jan 27, 2004
295
GB
Using ASP I make a SQL query to a database table and then return the recordset to a formatted table.
Code:
set MyConn = Server.CreateObject("ADODB.Connection")
MyConn.Open "Driver={SQL Server};Server=FTLive;Database=WorkLog;Uid=app;Pwd=;" 

Set rsData = Server.CreateObject("ADODB.Recordset")

strSQL = "select FaultNo, Fault, Resolution, UserID, FaultType, .......... etc
This works fine but I would also like to count the number of records returned. Searching the Web gave me this:
Code:
<%
Dim strCount 
strCount = 0
While NOT RSData.EOF AND NOT RSData.BOF
strCount = strCount + 1
RSData.MoveNext()
Wend
%>
However, when I use this then it appears that the recordet cannot be used again as the table is empty although the count is > 1

So is there any way I can use it more than once, or will I have to make two queries to SQL, one for data and one for the count of that data?

Many thanks.

Jonathan
 
Your data pointer is at the end of the recordset. Use RSData.MoveFirst to reset it to the start

If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top