469,270 Members | 1,097 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

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.CreateObject("ADODB.Connection")
oConn.Open Connstring
arrPlayers = split(strPlayers,",")

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

Set rs = nothing
oConn.close
Set oConn = nothing

Jul 31 '06 #1
3 957

Jul 31 '06 #2
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.CreateObject("ADODB.Connection")
oConn.Open Connstring
arrPlayers = split(strPlayers,",")

For i = Lbound(arrPlayers) to Ubound(arrPlayers)
if IsObject(rs) then set rs=nothing
strSQL = "Delete FROM playoffs p WHERE p.Playercode= " &
arrPlayers(i) set rs = oConn.execute(strSQL)
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 adExecuteNoRecords (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(strPlayers,",")

response.write "Ubound(arrPlayers) returns " & _
Ubound(arrPlayers) & "<br>"
for i = 0 to Ubound(arrPlayers)
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"
Aug 1 '06 #3
thanks for the pointers, the problem was a stray space char.

Aug 1 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by stealthwang | last post: by
36 posts views Thread by Remi Villatel | last post: by
5 posts views Thread by Andrew Young | last post: by
8 posts views Thread by Jim Langston | last post: by
6 posts views Thread by Raj | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.