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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Type:Item cannot be found

Status
Not open for further replies.

burningblue8

Programmer
Jul 24, 2002
8
GB
Blast those pesky option boxes.

This error appears when I try and populate the contents of a drop down box from one of the fields in my DB:

"Item cannot be found in the collection corresponding to the requested name or ordinal."


******** code************
while not rs.EOF
Response.Write &quot;<option value = &quot; & rs.fields(4).value & &quot;>&quot;
rs.movenext
wend

********************
and I'm getting this message back when I re-fresh the page.
I know the problem lies within the response.write statement, but cant figure out why it doesnt populate the box with the data from the selected field.

Help!!!
 
Can you try this:

response.write rs.fields.count
while not rs.EOF
Response.Write &quot;<option value = &quot; & rs.fields(4).value & &quot;>&quot;
rs.movenext
wend

I think when you refresh the recordset does not contain fields.
 
When I try that I get the:

Invalid character on the line
while not rs.eof

even though the syntax etc is correct??

Any ideas?
 
can you put the actual fieldname in instead??

Code:
<%
While NOT rs.EOF
    Response.Write  &quot;<OPTION VALUE=&quot; & rs(&quot;fieldname&quot;) & &quot;>&quot; 
    rs.MoveNext
Wend

%>
Tony
reddot.gif WIDTH=400 HEIGHT=2 VSPACE=3

 
Well I tried the field name, yet still get the same error as above.
(see error post for code)

Its one of those little things that drives you mad
 
The code I have got is the following and apart from staring at the screen for the past twenty minutes trying to figure this one out, I bet it is something simple:
All I am trying to do is populate a drop down box from a field in the db.



<font size=&quot;2&quot;><b><font size=&quot;2&quot; face=&quot;Verdana&quot;>Source <select id=source name=source>

<%
Set conn = server.CreateObject (&quot;ADODB.connection&quot;)
conn.Open Session(&quot;hfr_connectionstring&quot;)
Set rs = server.createobject (&quot;ADODB.recordset&quot;)
lssql = &quot;select source from booking&quot;

rs.open lssql, conn

Response.write rs.fields.count
while not rs.EOF
Response.Write &quot;<option value = &quot;& rs.fields(4).value & &quot; >&quot;
rs.movenext
wend

set rs = nothing
set conn = nothing

%>
</select>

the simple things are always the most annoying!!!

 
Well, what I see is that you are only selecting one element from your table (source), but you are telling it to write out the 5th element in the recordset (0 based array) - that is why you are getting a message that the element doesn't exist.

Try this:

<%
Set conn = server.CreateObject (&quot;ADODB.connection&quot;)
conn.Open Session(&quot;hfr_connectionstring&quot;)
Set rs = server.createobject (&quot;ADODB.recordset&quot;)
lssql = &quot;select source from booking&quot;

rs.open lssql, conn

Response.write rs.fields.count
while not rs.EOF
Response.Write &quot;<option value = &quot;& rs.fields(&quot;source&quot;).value & &quot; >&quot;
rs.movenext
wend

set rs = nothing
set conn = nothing

%>
 
If you still want to use the ordinal, you could try this:

Response.Write &quot;<option value='&quot; & rs.fields(0).value & &quot;'>&quot;
 
try this
Code:
Response.Write  &quot;<option value = &quot;& rs(&quot;source&quot;) & &quot; >&quot; 
[/code Tony
[img]http://www.phoenix-paints.co.uk/portfolio/images/reddot.gif WIDTH=400 HEIGHT=2 VSPACE=3[/img]
[URL unfurl="true"]http://www.phoenix-paints.co.uk/portfolio[/URL]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top