Forum Moderators: open

Message Too Old, No Replies

Looping problem!

         

zaneta

12:26 pm on Jun 4, 2004 (gmt 0)

10+ Year Member



I am running a database query and want to store some particular results into an array. What happens is that on every step of the loop the array fills only with the new values.

Here is a sample of my code.

var dbconn = Server.CreateObject("ADODB.Connection")
dbconn.Open(Application('DB_ConnectionString'))
var Hotels=new Array();
rs=getTypeHotels(3); // getTypeHotels: function that executes a query
while(!rs.EOF)
{
n=rs("HotelID");
Hotels.push(n);
Response.Write(Hotels)
rs.MoveNext();
}

If my recordset contains following values:0,1,2.

In the first loop I have:0
In the second loop I have (1,1) instead of (0,1)
In the third loop: (2,2,2), instead of (0,1,2)

What am I doing wrong? Please help me out!

aspdaddy

6:57 pm on Jun 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It looks like the push function is not moving elements down. This one works ok:


Public Sub push(n)
For i = me.end() to me.start() step -1
me.elements(i + 1) = me.elements(i)
Next
me.elements(me.start()) = n
End Sub

zaneta

4:11 pm on Jun 7, 2004 (gmt 0)

10+ Year Member



No, unfortunately the solution didnt work.
It must have something to do with the recordset itself, because when I am pushing scalar values in the array it works fine.

john_k

4:39 pm on Jun 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try changing

n=rs("HotelID")

to

n=rs("HotelID").Value

zaneta

5:28 pm on Jun 7, 2004 (gmt 0)

10+ Year Member



Yes!It worked!
Thank you so much,you saved my day.:-))