-
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.
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
%>
-
-
The way you've opened up your recordset, RecordCount will return -1.
You need to open up your recordset like:
Code:
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. :)
-
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):
Code:
Set cnn = Nothing
Set rst = Nothing