Executing Stored Procedure in loop duplicates row content

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

  1. #1

    Default Executing Stored Procedure in loop duplicates row content

    Hi,

    I am executing a stored procedure from a form post, when I execute the
    stored procedure it inserts a row for every checkbox checked, however it is
    populating the rows with the same content. It will only give the values from
    the first form object and insert the same to content to the value of "i".
    How can I make this insert the correct content into my DB?

    Thanks in advance for your answer

    Sean



    Set adoCmd = Server.CreateObject("ADODB.Command")
    adoCmd.ActiveConnection = db_conn
    adoCmd.CommandType = adCmdStoredProc
    adoCmd.CommandText = "sp_InsertOptions"

    for i = 1 to Request("chkOptions").count
    strOption = Request("chkOptions")(i)
    adoCmd.Parameters.Append
    adoCmd.CreateParameter("pProductID",adInteger)
    adoCmd.Parameters("pProductID") = ProductID
    adoCmd.Parameters.Append
    adoCmd.CreateParameter("pOptionValue",adVarChar ,adParamInputOutput,255)
    adoCmd.Parameters("pOptionValue") = Request("chkOptions")(i)
    adoCmd.Execute()
    next


    sean Guest

  2. Similar Questions and Discussions

    1. Error while executing stored procedure
      I get the following error message when I am trying to execute a stored procedure. It runs fine on my dev server but giving error in production. ...
    2. problems executing wscript_command stored procedure
      I'm trying to call the wscript_command stored procedure and use the ID of a DTS job as one of the input parameters. I am getting the message "Error...
    3. Executing a procedure from the cammand line
      I have a SQL command procedure, myproc.sql, containing sql statements. After I login to MySQL, how do I execute this procedure? mysql> ??????...
    4. DBD::Oracle not executing stored procedure properly...
      Hamish Whittal wrote: is this what you have in your code: "$$dbh->prepare($sql)"? david
    5. #22403 [Com]: PHP crashes when executing a sql procedure without parameters
      ID: 22403 Comment by: daniel dot beet at accuratesoftware dot com Reported By: cesararnold at yahoo dot com dot br...
  3. #2

    Default Re: Executing Stored Procedure in loop duplicates row content

    It's time for some debugging. See below:
    sean wrote:
    > Hi,
    >
    > I am executing a stored procedure from a form post, when I execute the
    > stored procedure it inserts a row for every checkbox checked, however
    > it is populating the rows with the same content. It will only give
    > the values from the first form object and insert the same to content
    > to the value of "i". How can I make this insert the correct content
    > into my DB?
    >
    > Thanks in advance for your answer
    >
    > Sean
    >
    >
    >
    > Set adoCmd = Server.CreateObject("ADODB.Command")
    > adoCmd.ActiveConnection = db_conn
    > adoCmd.CommandType = adCmdStoredProc
    > adoCmd.CommandText = "sp_InsertOptions"
    You should avoid using "sp_" to prefix your stored procedure names. "sp_"
    should be reserved for system stored procedures. You pay a performance
    penalty by using this prefix for you user-defined procedures since SQL will
    try to execute it as if it's a system procedure.
    >
    > for i = 1 to Request("chkOptions").count
    This should be:
    for i = 1 to Request.Form("chkOptions").count
    > strOption = Request("chkOptions")(i)
    Response.write "Request.Form(""chkOptions"")(" & i & ")"
    Response.write " contains " & strOption & "<BR>"

    > adoCmd.Parameters.Append
    > adoCmd.CreateParameter("pProductID",adInteger)
    > adoCmd.Parameters("pProductID") = ProductID
    > adoCmd.Parameters.Append
    > adoCmd.CreateParameter("pOptionValue",adVarChar
    > ,adParamInputOutput,255)
    > adoCmd.Parameters("pOptionValue") =Request.Form("chkOptions")(i)
    Why not use strOption?
    adoCmd.Parameters("pOptionValue") =strOption

    > adoCmd.Execute()
    > next
    If your debugging indicates that the loop is correctly setting the value of
    the strOption variable, then you may need to set the Command object's
    Prepared property to True.

    HTH,
    Bob Barrows

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"


    Bob Barrows Guest

  4. #3

    Default Executing Stored Procedure in loop duplicates row content

    Not sure if this will help, but try deleting your existing
    parameters after you execute.
    >-----Original Message-----
    >Hi,
    >
    >I am executing a stored procedure from a form post, when
    I execute the
    >stored procedure it inserts a row for every checkbox
    checked, however it is
    >populating the rows with the same content. It will only
    give the values from
    >the first form object and insert the same to content to
    the value of "i".
    >How can I make this insert the correct content into my DB?
    >
    >Thanks in advance for your answer
    >
    >Sean
    >
    >
    >
    > Set adoCmd = Server.CreateObject("ADODB.Command")
    >adoCmd.ActiveConnection = db_conn
    >adoCmd.CommandType = adCmdStoredProc
    >adoCmd.CommandText = "sp_InsertOptions"
    >
    >for i = 1 to Request("chkOptions").count
    > strOption = Request("chkOptions")(i)
    > adoCmd.Parameters.Append
    >adoCmd.CreateParameter("pProductID",adInteger)
    > adoCmd.Parameters("pProductID") = ProductID
    > adoCmd.Parameters.Append
    >adoCmd.CreateParameter
    ("pOptionValue",adVarChar ,adParamInputOutput,255)
    > adoCmd.Parameters("pOptionValue") = Request
    ("chkOptions")(i)
    > adoCmd.Execute()
    '' verify syntax for this
    for each p in adoCmd.Parameters
    adoCmd.Parameters(p).delete
    next

    >next
    >
    >
    >.
    >
    Keith 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