Click to See Complete Forum and Search --> : Strange Dictionary object Error.


kmalone
02-15-2005, 03:13 PM
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:



<!--#include file="dbconfile.asp"-->
<%
set Rs=server.createobject("adodb.recordset")
set cratedict=server.createobject("scripting.dictionary")
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>"
cratedict.add replace(trim(Rs("bindtype")),"_",""),Rs("rate")

Rs.movenext
wend
Rs.close
response.write "<hr>"
response.write cratedict.count&" count<br>"
g=cratedict.item("bp")
%>


/end code

Result is as follows:

bp - 1
bterms - 1
billtoperson - 2161
cdpd - 2
cdps - 0.1

------------------
5 count

ADODB.Field error '800a0d5c'

Object is no longer valid.

testdict.asp, line 15


/end result

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.

kmalone
02-15-2005, 06:13 PM
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.

jerm
09-17-2005, 09:24 PM
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!


Jeremy