Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dictionary object oddness 1

Status
Not open for further replies.

Laeg

Programmer
Nov 29, 2004
95
IE
I have done this 3 ways.

- manually adding items to a dictionary object (works)
- adding items to a dictionary object from an array (works)
- a recordset adding items to a dictionary object (fails)

What happens is that it adds the first item but once it does that it always seems to think that the other items already exist and it never adds them. So only the first item gets added.

Essentially the line below is false the first time but somehow true for all other values
Code:
If(oDict.Exists(l_oRs("foo")) = true)Then

l_oRs is my recordset, I'm stumped any ideas?

Code:
l_sSQL = "select 'a' as 'foo', 'b' as 'bar'" & _
		   " union" &_
		   " select 'c' as 'foo', 'd' as 'bar'"


 if (not(l_oRs.EOF and l_oRs.BOF)) Then
  	 do until l_oRs.EOF 
	 response.write "Does <b>" & l_oRs("foo") & "</b> exist?"
	   If(oDict.Exists(l_oRs("foo")) = true)Then
			response.write "yes, not adding<br/>"
	   Else
			response.write "no, adding<br/>"
			oDict.Add l_oRs("foo"), l_oRs("bar")
	   End if
  		l_oRs.MoveNext
  	 loop
  else
	response.write "No processing done"
  end if
 
Try changing:

oDict.Add l_oRs("foo"), l_oRs("bar")

To:

[tt][blue]oDict.Add [!]"" & [/!]l_oRs("foo"), [!]"" & [/!]l_oRs("bar")[/blue][/tt]

If this works for you, let me know and I will try to explain it.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Ok this works, thanks, what's it all about then :)
 
[tt] do until l_oRs.EOF
response.write "Does <b>" & l_oRs("foo") & "</b> exist?"

If(oDict.Exists(l_oRs("foo")[blue].value[/blue]) = true)Then
response.write "yes, not adding<br/>"
Else
response.write "no, adding<br/>"
oDict.Add l_oRs("foo")[blue].value[/blue], l_oRs("bar")[blue].value[/blue]
End if
l_oRs.MoveNext
loop
[/tt]
 
The recordset object is relatively deep in it hierarchy.

The 'correct' way to reference the value is a column is....

l_oRs.Fields.Item("foo").Value

The shorthand notation that you used (and many others use too) works because there are default properties. The recordset's default property is Fields. The fields default property is Item. The item's default property is Value.

If I'm not mistaken, in your original code, the FIELD object was getting stored in your dictionary object. By using [blue]"" & [/blue], you cause the recordset to return the .value property (instead it the Item property).

Make sense?

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
By using "" & , you cause the recordset to return the .value property (instead it the Item property).
Or looking at it another way... you can't append a string to an object, so it figured your intent was to append the string to the default value of the object.


#pragma DWIM // Do What I Mean!


 
Sheco,

That's exactly what I meant to say. Thank you for explaining it better than I could.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Thanks very much for replies, saved me a few hrs more of poking around
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top