473,378 Members | 1,439 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 1021

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: stealthwang | last post by:
I'm still very new to Python, after decideding to learn a true programming language (rather then a scripting language, i like to think i'm a intermediate PHP user). I decided for my first project I...
36
by: Remi Villatel | last post by:
Hi there, There is always a "nice" way to do things in Python but this time I can't find one. What I'm trying to achieve is a conditionnal loop of which the condition test would be done at...
0
by: Kingdom | last post by:
I Need some serious help here. strugling novis with ASP and javascript any help would be greatly appreciated The script below does exactly what I want it to do for each product on the two passes...
5
by: Andrew Young | last post by:
How do I loop thru a result set Without using a curosr?
8
by: Jim Langston | last post by:
There's the thing about iterating though a map or vector when you may delete one of the elements, where you simply assign the iterator to the map.erase() statement or increment it if you don't. ...
1
by: pauljturner99 | last post by:
Hi, I'm trying to pass a parameter from a for loop to the nested while loop but only the first counter is passed. Here is the code: dim ctr redim ctr(5) ctr(0) = 2 ctr(1) = 4 ctr(2) = 6
6
by: Raj | last post by:
We have a batch process that deletes about 7-8 million records every day & takes about 30-35 mins to complete. Is there a way to optimize deletes? Below is the statement delete from fact where...
2
by: recordlovelife | last post by:
So I am trying to display a title, date, and content of a wordpress blog. Word press provides nice drop in functions to get the job done with simple names like "the_title", and the "the_content" But...
8
by: Pivot_Tables | last post by:
Hi, I have created a recursive SQL Query in DB2 and it works fine until some point in the tree where the data gets into infinite loop. Below are some sample data from my relationship table. ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.