![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Mar 2005
Posts: 139
Rep Power: 4
![]() |
Hello all.
Simple concept here..i queryed my database (Access) , stored the resultes in a recordset, as usual Then i created a loop to put the contents of the recordset into an arry, but it only put one element in it. ..code below dim rArray(9) sql = "select rate from mort" set recset = adocon.execute(sql) do while (not recset.eof) for i=0 to recset.fields.count-1 rArray(i)= recset(i) next recset.moveNext loop response.write rArray(0) only the final element of the recordset is in the array did i set up the array right ? thanks |
|
|
|
|
|
#2 |
|
Professional Programmer
|
you forgot to increment i
![]() i++; After rArray(i)= recset(i); And, i don't think it's recset(i), ....... probably something like recset("mort"). But i may be way off here.
__________________
Don't take life too seriously, it's not permanent ! |
|
|
|
|
|
#3 |
|
Newbie
|
Yuck... even when doing a for...next loop, you still have to increment "i"? That's a messy language indeed
... I thought the incrementation of "i" was taken care of by the "next", as it was from my qb days (for i = 1 to 10 ... next i)That aside... If you're only dimming the array to have 9 elts, yet you're looping through all of the record sets, wouldn't you go out-of-bounds eventually? It's unrelated, but funky stuff happens when you mess with memory. Then again, I don't know VB, so you can pretty much disregard everything I just wrote ![]() |
|
|
|
|
|
#4 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 729
Rep Power: 4
![]() |
dim rArray(9) <-- Assumes that there are always 9 fields sql = "select rate from mort" set recset = adocon.execute(sql) do while (not recset.eof) for i=0 to recset.fields.count-1 rArray(i)= recset(i) <-- Sets rArray(i) to recset(i). This happens, for 0 to recset.fields.count -1, for each record. In other words, rArray in the end contains only the data from the last recordset next <-- Yes, i is incremented...handle the next of the fields recset.moveNext loop <-- handle the next record response.write rArray(0) <-- The first field of the last record. See above. You are copying the data from one array to another for each record and only returning the copied data after it has been overwritten several times.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270 |
|
|
|
|
|
#5 |
|
Professional Programmer
|
Damn .. i'm not giving advice on VB ever again :o
__________________
Don't take life too seriously, it's not permanent ! |
|
|
|
|
|
#6 |
|
Hobbyist Programmer
Join Date: Mar 2005
Posts: 139
Rep Power: 4
![]() |
Why is it overiding the previous element in the rArray ? my logic was:
when i is 0 then rArray(0)=recset(0) when i is 1 then rArray(1)=recset(1) when i is 2then rArray(2)=recset(2) etc... how can i fix it so that i have an array with all the elements of the recordset??? |
|
|
|
|
|
#7 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,435
Rep Power: 8
![]() |
Use a two-dimensional array:
Dim RecSet() ' find out how many fields and records there are Dim RecordCount As Integer = abc Dim FieldCount As Integer = xyz Redim RecSet(abc, xyz) |
|
|
|
|
|
#8 |
|
Hobbyist Programmer
Join Date: Mar 2005
Posts: 139
Rep Power: 4
![]() |
Why would it not work with a 1d array?
The purpose for the array with the contents of the recordset is... i had 7 fields (entry) in the database of numbers (mortgage rates) and i have a form where i input the new ones, but to do an sql update statement you have to specify what the current data is....ie: UPDATE mort SET rate1 = ' " & newRate &" ' WHERE rate1= oldValue...> thats the problem ...the old value i have to query the database to get that old value but there's 7 of them so..i figured i'd use an array (see my code above) |
|
|
|
|
|
#9 | |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,435
Rep Power: 8
![]() |
Quote:
| FieldA | FieldB | FieldC
--------+--------+--------+--------
Record1 | 1A | 1B | 1C
| | |
Record2 | 2A | 2B | 3C
| | |
Record3 | 3A | 3B | 3C
| | | |
|
|
|
|
|
|
#10 |
|
Hobbyist Programmer
Join Date: Mar 2005
Posts: 139
Rep Power: 4
![]() |
Thanks for all your help...but i think you misunderstood what i need...
I have to query my database for one type of information---> mortgage rates...no other info is needed to be in this array, as i need to use it in an update statement. If i want to update a field in the database (i will be updating all at once) i have to say change this value which you get from my form to this valu e (the one already in the database) .... thats where the problem is i wanted to do it all in 1 statement , thus i figured i needed an array with the data ...so...each field in my array has a mortgage rate in it how can i make a loop to copy the info from my recordset into an array ????? |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|