PDA

Click to See Complete Forum and Search --> : Help fill in the ?s


artsapimp
Aug 6th, 2000, 05:41 PM
Here is my code. I want LastRecord to represent the # of records in my database that meet the search criteria. Please help me finish this code.


<%
Dim SearchCriteria
Dim cnn
Dim rst
Dim LastRecord
Dim counter

SearchCriteria = Request.Form("Criteria")

Set cnn = Server.CreateObject("ADODB.Connection")
Set rst = Server.CreateObject("ADODB.Recordset")

cnn.Open "DSN=test"

rst.Open "Select * FROM test where name = " & SearchCriteria, cnn

LastRecord = ????????

for counter = 0 to LastRecord
Response.write (rst("Telephone(Counter)"))
Next

rst.Close
cnn.Close
%>

parksie
Aug 7th, 2000, 03:50 AM
Try rst.RecordCount

Aug 7th, 2000, 04:00 AM
The way you've opened up your recordset, RecordCount will return -1.

You need to open up your recordset like:
rst.Open "Select * FROM test where name = " & SearchCriteria, cnn, adOpenDynamic


You'll need to include the "adovbs.inc" file for VBScript to know what the hell "adOpenDynamic" means. If you haven't got this file then it's equal to 2. :)

Aug 7th, 2000, 04:05 AM
While I'm at it, you should really kill off your connection and recordset objects when you've finished too. (More server memory friendly.) :)

Stick this at the bottom of your script (after you've closed them):
Set cnn = Nothing
Set rst = Nothing