loop only deletes first pass

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jon Paal

    loop only deletes first pass

    why is this code only deleting on the first pass when there is more than one item in the array?

    checking the array shows all items are present, lower and upper bounds are correct

    if the array holds only one item it always works

    =============== =============== =============== =

    Set oConn = Server.CreateOb ject("ADODB.Con nection")
    oConn.Open Connstring
    arrPlayers = split(strPlayer s,",")

    For i = Lbound(arrPlaye rs) to Ubound(arrPlaye rs)
    if IsObject(rs) then set rs=nothing
    strSQL = "Delete FROM playoffs p WHERE p.Playercode= " & arrPlayers(i)
    set rs = oConn.execute(s trSQL)
    Next

    Set rs = nothing
    oConn.close
    Set oConn = nothing



  • Jon Paal

    #2
    Re: loop only deletes first pass -- problem found....




    Comment

    • Bob Barrows [MVP]

      #3
      Re: loop only deletes first pass

      Jon Paal wrote:
      why is this code only deleting on the first pass when there is more
      than one item in the array?
      checking the array shows all items are present, lower and upper
      bounds are correct
      if the array holds only one item it always works
      >
      =============== =============== =============== =
      >
      Set oConn = Server.CreateOb ject("ADODB.Con nection")
      oConn.Open Connstring
      arrPlayers = split(strPlayer s,",")
      >
      For i = Lbound(arrPlaye rs) to Ubound(arrPlaye rs)
      if IsObject(rs) then set rs=nothing
      strSQL = "Delete FROM playoffs p WHERE p.Playercode= " &
      arrPlayers(i) set rs = oConn.execute(s trSQL)
      Next
      >
      Set rs = nothing
      oConn.close
      Set oConn = nothing
      Nothing to do with your problem, but, in vbscript, calling the lbound
      function is a waste of time: it will always return 0.

      Again, unrelated to your problem, but why are you using a recordset to
      execute a query that returns no records? What a waste of time and resources.
      A simple

      oConn.execute strSQL,,129

      will be much more efficient. The 129 is the combination of two constants:
      adCmdText (1) which tells ADO that you are executing a string containing a
      sql statement, and adExecuteNoReco rds (128) which tells ADO not to construct
      a recordset because the query will not be returning records

      Now, onto your problem, which is going to require some debugging:

      response.write "strPlayers contains """ & strPlayers & """<br>"
      arrPlayers = split(strPlayer s,",")

      response.write "Ubound(arrPlay ers) returns " & _
      Ubound(arrPlaye rs) & "<br>"
      for i = 0 to Ubound(arrPlaye rs)
      val=arrPlayers( i)
      response.write "arrPlayers (" & i & ") contains """ & _
      arrPlayers(i) & """<br>"
      strSQL = "Delete FROM playoffs p WHERE p.Playercode= " & _
      val
      Response.Write "Executing """ & strSQL & """<BR>"
      oConn.execute strSQL,,129
      next

      Run the page and look at the results.
      If this does not give you the clue you need then show us the results

      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"


      Comment

      • Jon Paal

        #4
        Re: loop only deletes first pass

        thanks for the pointers, the problem was a stray space char.



        Comment

        Working...