Strange Dictionary object Error.
Need some help while my hair is still (mostly) intact. I've isolated this code out of a larger file (which i'm developing at the moment).
Code is as follows:
Rs.open "select top 5 bindtype, rate from current_rates where type='sp' and identifier=2051 order by bindtype",DatabaseConnection
while not Rs.eof
response.write replace(trim(Rs("bindtype")),"_","")&" - "&trim(Rs("rate"))&"<br>"
response.write cratedict.count&" count<br>"
Result is as follows:
bp - 1
bterms - 1
billtoperson - 2161
cdpd - 2
cdps - 0.1
ADODB.Field error '800a0d5c'
Object is no longer valid.
testdict.asp, line 15
Why would it give me the count on line 14, but not return the value on line 15?
Now, the thing is, i'm using dictonary objects in other scripts with no errors, and i can't for the life of me figure out what's going on.
no further responses needed, it turns out that my rate value needed to be trimmed. all is good, except for the state of my hair, but i can probably find most of it and paste it back on.
I also ran into this, and spent way too long trying to figure it out.
For future visitors to this thread:
It turns out that the two parameters passed to the scripting.dictionary "add" function are BYREFerence and not BYVALue, so it doesn't make a copy of the adodb.recordset data, but rather just puts a pointer to the adodb.recordset data. Of course, then you get finished with the rs (or move to the next record!) the dictionary.item() pointer goes to the wrong place, and then the adodb error.
So run your parameters through any function (trim, int) or assign them to a variable ( a=rs(0) : b=rs(0) : odict.add a,b ) and you won't get the weird errors, or pull out any hair!
This has caught me out a couple of times before. My preferred solution is to use the Value property:
Perhaps a tad more elegant than Trim(), using a variable, etc.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)