stumped on Dictionary object

Results 1 to 2 of 2

Thread: stumped on Dictionary object

  1. #1
    Corin Guest

    Default stumped on Dictionary object

    This code;dim content(1) <BR><BR>Set content(0) = server.CreateObject("Scripting.Dictionary") <BR> <BR>While Not rs.EOF<BR>response.write ("&#060;FONT COLOR=&#039black&#039&#062;Name= " & rs.fields("contentPageID") & " , Content= " & rs.fields("contentName") & "<BR>&#060;/FONT&#062;")<BR><BR>&#039content(0).Add rs.fields("contentPageID"), rs.fields("contentName")<BR> <BR>rs.movenext<BR> <BR>WEND<BR><BR>Gives me the corresct results;<BR><BR>Name= 1 , Content= search<BR>Name= 2 , Content= news<BR>Name= 3 , Content= hotshots<BR>Name= 4 , Content= metrics<BR>Name= 5 , Content= search2<BR>Name= 6 , Content= ad1<BR>Name= 7 , Content= jobs<BR>Name= 8 , Content= ad2<BR>Name= 9 , Content= discussion<BR><BR>But if I uncomment the line to fill the dictionary object;<BR><BR>content(0).Add rs.fields("contentPageID"), rs.fields("contentName")<BR><BR>I get the following error;<BR><BR>Name= 1 , Content= search<BR>Name= 2 , Content= news<BR><BR>Microsoft VBScript runtime error &#039 800a01c9&#039 <BR><BR>This key is already associated with an element of this collection <BR><BR>/ieg/test.asp, line 32 <BR><BR>as you can see from the working example there are no duplicate keys.<BR><BR>Any help is appreciated,<BR><BR><BR>

  2. #2
    KPW Guest

    Default RE: stumped on Dictionary object

    I have had this happen to me as well. What you want to do is first assign the values of your database fields to variables, then use those variables when filling your dictionary.<BR><BR>&#060;%<BR>...<BR>contentPageID = rs.Fields("contentPageID")<BR>contentName = rs.Fields("contentName")<BR><BR>content(0).Add contentPageID, contentName<BR>...<BR>%&#062;<BR><BR>I think that should work for you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts