• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 834
  • Last Modified:

Classic ASP Command Object

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"

  • 3
  • 2
1 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)
KeithMcElroyAuthor Commented:
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:
Ok it should be this way
cmd.Parameters.Append(cmd.CreateParameter("unique_key", adChar, adParamInput, Len(uniquekey), uniquekey))
KeithMcElroyAuthor Commented:
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!
KeithMcElroyAuthor Commented:
Works like a charm.
thanks for the help.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now