Results 1 to 4 of 4

Thread: Help fill in the ?s

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2000
    Posts
    323
    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
    %>
    If you think education is expensive, try ignorance.

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Try rst.RecordCount
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    Guest
    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.

  4. #4
    Guest
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width