Classic ASP  Command Object

Posted on 2012-09-11
Last Modified: 2012-09-11
I am new to using the command object and need it for various reasons on a project, so trying to get a simple example working

The following code fails on the cmd.Parameters.Append line.
If I comment that out it does not return an error.

Can anyone help me out with spotting what I am missing and help me finish out this example?

Thanks a mil,

dim uniquekey
uniquekey = "0685383D-B85D-4481-95E6-13BEE6727F4A"

dim data_source, fieldstr, sql_query, rs, con, cmd
' Set datasource
data_source = "Provider=SQLOLEDB;Server=erpdb\ONESolution;Database=production_finance;UID=SPS_SQLAdmin;PWD=1S0luti0n;"

      fieldstr = ""
      for each node in oContentX.selectnodes("//element")
            fieldstr =  fieldstr &   node.getAttribute("id") & ", "
      fieldstr = Left(fieldstr, Len(fieldstr) - 2)

CONST adCmdText = 1
CONST adChar = 129
CONST adParamInput = 1

set con = Server.CreateObject("ADODB.Connection")
con.Open data_source
set rs = Server.CreateObject("ADODB.Recordset")
set cmd = Server.CreateObject("ADODB.Command")
set cmd.ActiveConnection = con

cmd.CommandType = adCmdText
cmd.CommandText = "SELECT " & fieldstr & " FROM "  &  " pe_name_mstr " & " WHERE unique_key=?"
response.write Request("uniquekey")
cmd.Parameters.Append(cmd.CreateParameter("unique_key", adChar, adParamInput, Len(uniquekey), uniquekey)
'Set rs = cmd.Execute

      response.write "will use rs here"

Question by:KeithMcElroy
    LVL 58

    Accepted Solution

    cmd.Parameters.Append(cmd.CreateParameter("unique_key", adChar, adParamInput, Len(uniquekey), uniquekey)

    Should be
    cmd.Parameters.Append(cmd.CreateParameter("unique_key"), adChar, adParamInput, Len(uniquekey), uniquekey)

    Author Comment

    Thanks for spotting that.
    I must be blind.  This sample that follows is from a sample page I was given on a previous post and it seems like it wraps all of the args.  I will get back on the server and try it your way.  It would be great if I could understand it more though why this example is wrong...

    Setting up Parameters in ASP:
    dbCommand.Parameters.Append (dbCommand.CreateParameter("username", adChar, adParamInput, Len(username), username))
    dbCommand.Parameters.Append (dbCommand.CreateParameter("pwd", adChar, adParamInput, Len(pwd), pwd))
    Set rs = dbCommand.Execute

    url of the above example:
    LVL 58

    Expert Comment

    Ok it should be this way
    cmd.Parameters.Append(cmd.CreateParameter("unique_key", adChar, adParamInput, Len(uniquekey), uniquekey))

    Author Comment

    Yes, I really am blind. I missed the final ')'.
    Thanks a mil.  I will get on the server, test, advise and reward points.
    I appreciate it!

    Author Comment

    Works like a charm.
    thanks for the help.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
    I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now