0

The following is my VBScript code in a classic ASP application:

    Set newParam = command.CreateParameter(Name, ParamType, 1)
    newParam.Value = Value
    command.Parameters.Append(newParam)
    command.Parameters(Name) = Value

The 'Append' line always breaks with the following error:

enter image description here

It seems to make no difference whether the command has a valid active connection or whether the connection is open (the connection is to an Oracle database).

The 'Name', 'ParamType' and 'Value' parameter values are correct.

What is missing? Or could be wrong?

Thanks

4
  • second line is not needed (newParam.Value = Value) Commented Mar 22, 2013 at 14:44
  • What exactly is the value for ParamType? You're not specifying a Size, which may be required for the data type you select. Commented Mar 23, 2013 at 4:12
  • Instead of command.Parameters.Append have you considered command.Parameters.Refresh ? This might save you a lot of effort. Commented Mar 24, 2013 at 20:39
  • I would aldo look into two other things: 1) I have seen many debuggers (VS 2008) report one line off. I.e. try to verify if that is the erroring line, and not the CreateParameter., and 2) are the constants for param type, if you're using constants, in scope? Commented Mar 25, 2013 at 5:38

1 Answer 1

2

Remove the parentheses from the Append instruction. In this context their meaning is "pass argument by value", not "parameter list" (see this article). Also put the value assignment after the parameter assignment.

Set newParam = command.CreateParameter(Name, ParamType, 1)
command.Parameters.Append newParam
newParam.Value = Value

Do you still receive the error with the Append instruction? If so, something is wrong with your Name or ParamType arguments.

Sign up to request clarification or add additional context in comments.

2 Comments

Removing the parentheses when calling Subs is good advice in general, but I'm not sure it makes a difference here. Whether or not your pass the argument ByVal or ByRef, it's still going to be a reference to the same Parameter object.
@CheranShunmugavel Most likely it won't make a difference (it didn't when I tested with some sample values), but I'd remove them anyway, just to be on the safe side.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.