SPs/Command Object/Parameters Problem

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default SPs/Command Object/Parameters Problem

    I've searched through google groups and cannot find an answer to this:
    My application passes values from a form to a page that requests them and
    sets them as parameters which are then passed to the SP. The SP then updates
    a table with these values.

    The problem is that not all of the values need to be entered on the form and
    therefore there can be empty parameters being passed to the stored
    procedure.
    In the SP I've made sure all the default values are set so there is no
    problem there but it's the calling of the SP with empty parameters that is
    causing problems.

    What would be ideal is if I could conditionally pass parameters, e.g.:
    if varTitle <> "" then
    .Parameters.Append
    ..CreateParameter("@title",adLongVarChar,adParamIn put,len(varTitle),varTitle)
    end if

    But this gives errors.

    Please can anyone tell me if there is a way of doing this or if I am doing
    something wrong? I understand I could dynamically build and execute an
    update query in ASP but would prefer to use SPs as everything else uses
    them.

    TIA

    chopper


    Chopper Guest

  2. Similar Questions and Discussions

    1. get command line parameters in plugin (i.e. argc & argv)
      hi, i'm searching in the api documentation how to get parameters passed to acrobat when i call c:\acrobat\acrobat.exe ___mypdf.pdf -C ashjs7...
    2. using Command to set Parameters and Recordset to retrive the Query
      Hi guys, withou using SP, I want to be able to add a Parameter to the SQL Query and retrive the Recordset so I can use the Paging property under...
    3. Projector with command line parameters
      Hello, is it possible to build a projector, which can be started with command line parameters? If yes, how can I get access to this parameters...
    4. Command Parameters
      Can someone tell me why the following code does not work ? It does not crash or cause errors and it creates a new row in the table "tblusers" but...
    5. Passing parameters to a Perl Script from Command Line (Linux)
      Hi, I'm fairly new to both programming in shell script (linux) and in programming in perl. I need to pass a parameter to the perl script from...
  3. #2

    Default Re: SPs/Command Object/Parameters Problem

    Pass the missing values as Nulls. Instead of this:
    > if varTitle <> "" then
    > .Parameters.Append
    >
    ..CreateParameter("@title",adLongVarChar,adParamIn put,len(varTitle),varTitle)
    > end if
    You want to do this:
    if varTitle = "" then
    varTitle = Null
    end if
    .Parameters.Append
    ..CreateParameter("@title",adLongVarChar,adParamIn put,len(varTitle),varTitle)

    Do you really need a Command object? If your SP doesn't have any output
    parameters and you're not interested in evaluating the Return value, then
    you don't need a Command object. You can use the
    stored-procedure-as-connection-method technique. A quick Google search
    should provide details.

    HTH,
    Bob Barrows

    Chopper wrote:
    > I've searched through google groups and cannot find an answer to this:
    > My application passes values from a form to a page that requests them
    > and sets them as parameters which are then passed to the SP. The SP
    > then updates a table with these values.
    >
    > The problem is that not all of the values need to be entered on the
    > form and therefore there can be empty parameters being passed to the
    > stored procedure.
    > In the SP I've made sure all the default values are set so there is no
    > problem there but it's the calling of the SP with empty parameters
    > that is causing problems.
    >
    > What would be ideal is if I could conditionally pass parameters, e.g.:
    > if varTitle <> "" then
    > .Parameters.Append
    >
    ..CreateParameter("@title",adLongVarChar,adParamIn put,len(varTitle),varTitle)
    > end if
    >
    > But this gives errors.
    >
    > Please can anyone tell me if there is a way of doing this or if I am
    > doing something wrong? I understand I could dynamically build and
    > execute an update query in ASP but would prefer to use SPs as
    > everything else uses them.
    >
    > TIA
    >
    > chopper


    Bob Barrows Guest

  4. #3

    Default Re: SPs/Command Object/Parameters Problem


    "Bob Barrows" <reb01501@NOyahoo.SPAMcom> wrote in message
    news:OeZsNRljDHA.2140@TK2MSFTNGP09.phx.gbl...
    > Pass the missing values as Nulls. Instead of this:
    > > if varTitle <> "" then
    > > .Parameters.Append
    > >
    >
    ..CreateParameter("@title",adLongVarChar,adParamIn put,len(varTitle),varTitle)
    > > end if
    >
    > You want to do this:
    > if varTitle = "" then
    > varTitle = Null
    > end if
    > .Parameters.Append
    >
    ..CreateParameter("@title",adLongVarChar,adParamIn put,len(varTitle),varTitle)
    >
    > Do you really need a Command object? If your SP doesn't have any output
    > parameters and you're not interested in evaluating the Return value, then
    > you don't need a Command object. You can use the
    > stored-procedure-as-connection-method technique. A quick Google search
    > should provide details.
    >
    > HTH,
    > Bob Barrows
    >
    Thanks for your reply.
    I get a type mismatch error when creating the parameter when the argument is
    null :(
    Are you sure null is a valid argument with the adLongVarChar type?

    chopper


    Chopper Guest

  5. #4

    Default Re: SPs/Command Object/Parameters Problem

    Chopper wrote:
    >
    > Thanks for your reply.
    > I get a type mismatch error when creating the parameter when the
    > argument is null :(
    > Are you sure null is a valid argument with the adLongVarChar type?
    >
    > chopper
    Oh, my bad. I did not read closely enough.

    With a string parameter, there should be no problem passing an empty string.
    You do need to make sure your variable contains an empty string (and isn't
    simply empty). You can use CStr to guarantee that.

    With number or datetime types, I have found the need to set the values to
    Null when values were not supplied by the user.

    Bob Barrows



    Bob Barrows Guest

  6. #5

    Default Re: SPs/Command Object/Parameters Problem

    <snip>
    > With a string parameter, there should be no problem passing an empty
    string.
    > You do need to make sure your variable contains an empty string (and isn't
    > simply empty). You can use CStr to guarantee that.
    >
    > With number or datetime types, I have found the need to set the values to
    > Null when values were not supplied by the user.
    >
    > Bob Barrows
    >
    >
    That did it!
    Many thanks for your help.


    Chopper Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139