Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6024427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:09:14+00:00 2026-05-23T04:09:14+00:00

I want to simply retrieve a single record from a database in a classic

  • 0

I want to simply retrieve a single record from a database in a classic ASP page. The code below basically works, but there are a couple problems I need help solving:

1) I want to see if a record was returned or not. result is not Nothing, so the redirect at the bottom is never performed. contact.RecordCount always returns -1, so I apparently can’t use that either. Oddly, trying to access RecordCount outside the function throws an “Object doesn’t support this property or method: ‘RecordCount'” error.

2) I’ve read about disconnected queries and have seen examples where the connection and command are closed and/or set to Nothing at the end of the function. Is there a definitive best practice on what I should do?

3) Will using a parameterized query fully protect me from SQL injection, or do I need to manually remove dangerous words and characters?

function GetContactByUsername(username)
    Dim conn, command, param, contact
    set conn = server.CreateObject("adodb.connection")
    conn.Open Application("DatabaseConnectionString")

    Set command = Server.CreateObject("ADODB.COMMAND")
    set command.ActiveConnection = conn
    command.CommandType = adCmdText
    command.CommandText = "Select * from MY_DATABASE.dbo.Contact where Username = ?"

    Set param = command.CreateParameter ("Username", adVarWChar, adParamInput, 50)
    param.value = username
    command.Parameters.Append param 

    Set contact = Server.CreateObject("ADODB.RECORDSET")

    contact.Open command

    Response.Write contact.RecordCount   '' always -1

    set GetContactByPurlCode = contact
end function

dim result
result = GetContactByUsername(Request.QueryString("username"))

if result is Nothing then     '' never true
    Response.Redirect "/notfound.asp"
end if

FirstName = Trim(result("FirstName"))
LastName = Trim(result("LastName "))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:09:15+00:00Added an answer on May 23, 2026 at 4:09 am

    1) To check for a lack of records, use rs.EOF, not “Is Nothing.” The RecordSet object is always an object. It’s just that sometimes it doesn’t have any rows.

    If you want to use RecordCount but are getting -1, then switch to a client-side cursor (adUseClient).

    2) No definitive best-practice here, but I’ve personally always closed the Connection and Command, and have not had much in the way of performance problems. Connection objects are particularly precious, so close them as early as possible on high volume pages.

    3) Yes, parameterizing your variable is perfect, unless you are calling a stored procedure that constructs a dynamic query.

    By the way, you should avoid “SELECT *” as that will cause you to return more data than needed and is a maintenance problem waiting to happen.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I simply want to call a swing action from my own popup menu. But
Pretty straightforward, but I just want to know which is faster. I think simply
The subject says it all... I simply want Xcode to make a beep or
In .net, I have an inherited control: public CustomComboBox : ComboBox I simply want
I've googled around and can't find a clear answer. I simply want to start
I'm struggling to think of a good way to use linq2sql, simply I want
I want to know how to simply publish over http = much like Mercurial
I want to make a table that simply has two integer columns to serve
How do I simply get GET and POST values with JQuery? What I want
I'm experimenting a bit with the new canvas element in HTML. I simply want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.