473,732 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dictionary Object

Wondering if someone can give me a hand with something that I'm sure is
really easy - but damned if I know what I'm doing wrong. I'm trying to read
the contents of a database into an ASP dictionary object. However I'm
getting the error

Microsoft VBScript runtime error '800a01c9'
This key is already associated with an element of this collection
/test.asp, line 21

There's definately no repeated data in either column, it's currently only
test data, one column is 1,2,3,4 etc the other is a,b,c,d. I can confirm
it's reading the data properly if I use response.write instead of d.add
The code I'm using is this:

Set rsCount = Server.CreateOb ject ("ADODB.Records et")
sqlView = "select data,number from tblTemp"
Set d=Server.Create Object("Scripti ng.Dictionary")

rsCount.Open sqlView, "dsn=dsn_hits_2 "
do while not rsCount.eof
d.add rsCount("number "),rsCount("dat a")
rsCount.MoveNex t
loop
rsCount.close

Set rsCount = Nothing


Many thanks in advance.
Jul 19 '05 #1
6 6335
When you add an item to the dictionary object, the key must be unique. The
key is the first argument in the add method, which in this case, is
rsCount("number "). What that error means is that it's hitting a record that
has rsCount("number ") with the same value as another record that has already
been inserted into the dictionary object. i.e.
number data
1 Joe
2 Kelly
3 Frank
2 Jorg

When it gets to the Jorg record and tries to use 2 as the key, that'll throw
an error since the Kelly item in the dictionary object already has a key of
2.

Possible Solutions:

Use an array instead of a dictionary object.

Use the primary key in your recordset if the key doesn't matter.

Use a counter for the key and increase it by one in your loop if the key
doesn't matter.

Probably some other things.

Ray at work
"Johnny Klunk" <johnnyklunk@:r em0ve-this:johnnyklun k.com> wrote in message
news:be******** **@sparta.btint ernet.com...
Wondering if someone can give me a hand with something that I'm sure is
really easy - but damned if I know what I'm doing wrong. I'm trying to read the contents of a database into an ASP dictionary object. However I'm
getting the error

Microsoft VBScript runtime error '800a01c9'
This key is already associated with an element of this collection
/test.asp, line 21

There's definately no repeated data in either column, it's currently only
test data, one column is 1,2,3,4 etc the other is a,b,c,d. I can confirm
it's reading the data properly if I use response.write instead of d.add
The code I'm using is this:

Set rsCount = Server.CreateOb ject ("ADODB.Records et")
sqlView = "select data,number from tblTemp"
Set d=Server.Create Object("Scripti ng.Dictionary")

rsCount.Open sqlView, "dsn=dsn_hits_2 "
do while not rsCount.eof
d.add rsCount("number "),rsCount("dat a")
rsCount.MoveNex t
loop
rsCount.close

Set rsCount = Nothing


Many thanks in advance.

Jul 19 '05 #2

"Ray at <%=sLocation% >" <as*@me.forit > wrote in message
news:O3******** ******@TK2MSFTN GP12.phx.gbl...
When you add an item to the dictionary object, the key must be unique. The key is the first argument in the add method, which in this case, is
rsCount("number "). What that error means is that it's hitting a record that has rsCount("number ") with the same value as another record that has already been inserted into the dictionary object. i.e.

Hi,
Thanks for the response. The thing is, the data is definately not repeated.
I entered the data manually to test and make there's no error. It's just
1,2,3,4 etc..
That's a good idea with the primary key. I've just tested again, setting
each of my columns as the primary key to ensure the database has no repeated
entries. I'm still getting the same thing. It's driving me nuts!
Jul 19 '05 #3
Try this then and look:

rsCount.Open sqlView, "dsn=dsn_hits_2 "
do while not rsCount.eof
response.write rsCount("number ") & "," & rsCount("data") &
"<br />"
rsCount.MoveNex t
loop
rsCount.close

Ray at work
"Johnny Klunk" <johnnyklunk@:r em0ve-this:johnnyklun k.com> wrote in message
news:be******** **@hercules.bti nternet.com...

"Ray at <%=sLocation% >" <as*@me.forit > wrote in message
news:O3******** ******@TK2MSFTN GP12.phx.gbl...
When you add an item to the dictionary object, the key must be unique. The
key is the first argument in the add method, which in this case, is
rsCount("number "). What that error means is that it's hitting a record

that
has rsCount("number ") with the same value as another record that has

already
been inserted into the dictionary object. i.e.

Hi,
Thanks for the response. The thing is, the data is definately not

repeated. I entered the data manually to test and make there's no error. It's just
1,2,3,4 etc..
That's a good idea with the primary key. I've just tested again, setting
each of my columns as the primary key to ensure the database has no repeated entries. I'm still getting the same thing. It's driving me nuts!

Jul 19 '05 #4

"Ray at <%=sLocation% >" <as*@me.forit > wrote in message
news:e7******** ******@TK2MSFTN GP12.phx.gbl...
Try this then and look:

rsCount.Open sqlView, "dsn=dsn_hits_2 "
do while not rsCount.eof
response.write rsCount("number ") & "," & rsCount("data") &
"<br />"
rsCount.MoveNex t
loop
rsCount.close

Ray at work


Ray,
Thanks again for the quick response :) I've actually tried that idea - but
to be sure, to be sure I pasted your code in to make sure the results
matched. I've copy-pasted the output from test.asp below. You can see why
this is driving me nuts ! As far as I see, every row has different data in
each column.

a,1
b,2
c,3
d,4
e,5
f,6
g,7


Jul 19 '05 #5
"Johnny Klunk" <johnnyklunk@:r em0ve-this:johnnyklun k.com> wrote in
message news:be******** **@sparta.btint ernet.com...
d.add rsCount("number "),rsCount("dat a")


Try:
d.add rsCount.Fields. Item("number"). Value,
rsCount.Fields. Item("data").Va lue

Also you can take advantage of the fact that the dictionary object will
create/overwrite a key based on whether it exists or not:
d(rsCount.Field s.Item("number" ).Value) =
rsCount.Fields. Item("data").Va lue

However this method wreaks of "programmin g by side effect" so if the
first method work, use that.

HTH
-Chris
Jul 19 '05 #6
"Johnny Klunk" <johnnyklunk@:r em0ve-this:johnnyklun k.com> wrote in
message news:be******** **@sparta.btint ernet.com...
d.add rsCount.Fields. Item("number"). Value, rsCount.Fields. Item("data").Va lue

Yep, thats worked. Superb, thanks so much. No idea why my bit of

code didn't work, but I'm glad for a solution.

Cheers

You code was attempting to set the dictionary key to a field Object, not
it's value. Whenever possible, try to explicitly reference values. When
you reference the value of a field object implicitly (i.e.
rsCount("number ") you're asking the parser to do the following:

1. Determine the default property/method for the rsCount object, the
Fields collection
2. Determine the default property/method for the Fields collection, the
Item method
3. Determine the default property/method for the Item object, the Value
property
4. Determine if the Value property is an object
5. If it is an object do the whole object model default method/property
traversal thing again.
6. If not, return the Value

All of these steps are also dependent on the context in which they are
called. So sometimes the default thing happens, sometime it doesn't.
There are also a lot more going on before, between and after each of
these steps, but you get the idea. Always better to explicitly identify
the "value" you want.

HTH-
Chris

Jul 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3590
by: none | last post by:
or is it just me? I am having a problem with using a dictionary as an attribute of a class. This happens in python 1.5.2 and 2.2.2 which I am accessing through pythonwin builds 150 and 148 respectively In the sample code you see that I have class Item and class Dict class Dict contains a dictionary called items. The items dictionary will contain instances of Item that are keyed off of the Item name. In __main__ I create two...
8
5590
by: Rodd Snook | last post by:
I have an application which makes extensive use of the Scripting.Dictionary object. I'm not doing anything silly like putting them outside the page scope -- just creating quite a few of them and stuffing quite a lot of data (from and MS SQL database) into them. On Windows 2000 server, everything is fine. If the data structures get really big it slows down, but for normal operation it's no problem. Recently our hosting provider moved to...
26
4063
by: Alan Silver | last post by:
Hello, I have a server running Windows Server 2003, on which two of the web sites use the MegaBBS ASP forum software. Both sites suddenly developed the same error, which seems to be connected to the dictionary object. After some tinkering, I whittled it down to the following (complete) ASP... <%@ CodePage=65001 Language="VBScript"%>
2
3422
by: jg | last post by:
I was trying to get custom dictionary class that can store generic or string; So I started with the example given by the visual studio 2005 c# online help for simpledictionay object That seem to miss a few things including #endregion directive and the ending class } Is there not a simple way like in dotnet vb? I managed to get the sample to code to this:
1
9259
by: john wright | last post by:
I have a dictionary oject I created and I want to bind a listbox to it. I am including the code for the dictionary object. Here is the error I am getting: "System.Exception: Complex DataBinding accepts as a data source either an IList or an IListSource at System.Windows.Forms.ListControl.set_DataSource(Object value)
4
2326
by: Betina Andersen | last post by:
I have a dictionary object, then I create a new dictionary object and sets it equal to my original, then I pass the new dictionary object to a function that changes some of my values - but then my original dictionary also gets changed and that was not the intention, can someone explain to me why it behaves that way and how do I avoid it, så I van have different dictionary objects? Thanks Betina
4
14757
by: NullQwerty | last post by:
Hi folks, I have a Dictionary which contains a string key and an object value. I want the object value to point to a property in my class and I want it to be by reference, so that later on I can change the value of the property through the dictionary. I am having difficulty making the value be by reference. Is this possible? I've even tried unsuccessfully to use unsafe code with pointers.
3
4183
by: wildThought | last post by:
If I have an object that contains a generic dictionary inside of it, how do I get access to its properties such as count?
6
10177
by: GiJeet | last post by:
hello, I'm trying to use a dictionary as a class member. I want to use a property to get/set the key/value of the dictionary but I'm confused as how to use a dictionary as a property. Since there are 2 parts, I don't know how to setup the get/sets. I tried searching but could not find any examples. I'd appreciate an example of how to get/ set the two parts of a dictionary via a property of a class. tia
2
3136
by: Andy B | last post by:
I don't know if this is even working or not but here is the problem. I have a gridview that I databound to a dictionary<string, stringcollection: Contract StockContract = new Contract(); StockContract.Dictionary = ContractDictionary<string, string>(); GridView1.DataSource=StockContract.Dictionary; So far so good. Now I assign something to the Dictionary collection through some textboxes and a button:
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9447
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9307
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.