This is my first post here at ERT. Hope you guys can help me out with this one.
As opposed to some other places, help here may be a little different. Rather than just debugging your code for you, we might suggest using cleaner logic and help you rewrite it into something more efficient and more maintainable.
In looking at your code:
1. you are creating new objects every time you query the database,
2. you have at least one object you do not dispose of when finished, and
3. you perform some actions in VBScript that the database could handle more effiently.
If you get a large number of simultaneous hits on this page (the goal of every shopping cart) your server is going to consume memory which will not be released quick enough to keep your application from crashing. Even if you do not get very many simultaneous hits, as the code is written, it is going to be unstable and slower than necessary.
Reading your post and the comments in your code, I think I know what you are trying to do but it isn't completely clear. So lets start with the problem definition.
You say you have some "Primary" product that is going to be displayed. On that page you wish to display some alternative choices.
To determine which alternative choices (products) to also show you initially just picked two at random.
Now you wish to refine this further.
If the primary product has one or two additional product codes then you will choose alternative product choices related to those additonal product codes.
Is this correct?
As to the specific question. When you have only one additional product code your query fails with "
either rs.bof or rs.eof is true". This is a different logical condition than
not rs.eof.
For example.
Set rs = conn.execute(query)
if rs.bof and rs.eof then
' No records were returned
else if rs.eof
' I may or may not have records, but
' I know my recorset cursor is at the end
end if
I suspect, when we look at your query, it returns no records when you only supply one additional product code. If so, your test for eof is not sufficient. But I suggest we look at a better way of doing all of this, and especially cleaning up the creation and disposal of recordset and connection objects. We can fix the query later, and may not even use that style of query after we clean up the rest of the code.
First, let be know if I understand the problem description, then you can decide how to proceed.