Forum Moderators: open
The error is always on the third go round the loop when putting the third key in the dictionary. It doesnt matter which table I select from - whether I order ASC or DESC, DISTINCT or not.
The error says I am trying to insert a duplicate key, but this isnt possible as ID in the table is unique constraint and even SELECT DISTINCT gives the same error.
ID in the tables is datatype tinyint,smallint or int and may be non-consecutive numbers, but this doesnt seem to make a difference.
set oDict = server.createobject("Scripting.Dictionary")
fill oDict,"SELECT ID,SomeValue from SomeTable"
sub fill ( d,sql)
dim objConn, objRS, strSQL
set objConn=Server.CreateObject("ADODB.Connection")
openDB( objConn )
set objRS = objConn.Execute ( strSQL )
while not objRS.EOF
d.Add objRS(0), objRS(1)
objRS.MoveNext
wend
closeRS(objRS)
closeDB(objConn)
end sub
I puts in two values and fails on the third, every time.
Now if I change this line:
d.Add objRS(0), objRS(1)
to:
d.Add cstr(objRS(0)), objRS(1)
Everything works fine in the sub, but when come to use the dictonary outside the sub, when I read from it it gives an exception.
:(
sub fill ( d,sql)
dim objConn, objRS, strSQL
set objConn=Server.CreateObject("ADODB.Connection")
openDB( objConn )
set objRS = objConn.Execute ( strSQL )
while not objRS.EOF
'd.Add objRS(0), objRS(1)
objConn.Execute(Your insert SQL here)
objRS.MoveNext
wend
closeRS(objRS)
closeDB(objConn)
end sub