ASP / Item cannot be found in the collection corresponding to the requested name or ordinal

Posted on 2006-05-30
Last Modified: 2010-04-17
I know you guys have seen this error message before; Most of the field names have a space between them.  For Example: Job id, add no, telf no... etc.  I don't know how to define them on this statement:

response.write("<option value=""" & rs("job id") & """>")

I've already tried to put [] around "job id", also I removed the quotes around it  but it doesn't work.  Do you have any other ideas??

ADODB.Recordset (0x800A0CC1)
Item cannot be found in the collection corresponding to the requested name or ordinal.

Question by:skyler99
    LVL 3

    Expert Comment

    field names should never conatin spaces, the database system should have trown error when the table was being made. Unless job id is an alias for a field, but even that should have an underscorel.

    Try referencing it with rs("job")
    LVL 9

    Expert Comment

    jmar is correct, field names should never contain spaces and most tech-types will turn green/purple if they see it (although it is technically valid in many DBs, MS Access immediatley springs to mind but query via DAO/ADO/.NET wil usually require the field wrapped in square brackets when referencing)

    If you must Separate words in a field use an underscore '_' character but preferably do it Correctly 'JobID' or 'EmployeeName'.

    However in this case one or more of these solutions may work but most likely the third one

    response.write("<option value=""" & rs("[job id]") & """>")
    response.write("<option value=""" & rs("job id").value & """>")

    response.write("<option value=""" & rs("[job id]").value & """>")

    in your example you are actually returning the field *object* rather than the *value* of the field.


    Author Comment

    This is an Access database 2000.  

    I just try this.
    response.write("<option value=""" & rs(0).value & """>") works fine.
    LVL 9

    Accepted Solution

    From your comment i would say that my second suggestion should work

    can you post the query used to populate the rs? are you sure that 'job id' is a valid field within the query?
    for t=0 to rs.fields.count
    reponse.write "<br>"  & rs(t).name & "<br>"
    next t

    that will tell you exactly what the field name is at the time of query. Also if you are doing a

    Select * from Table

    i would suggest doing a

    select [Table]. [Field 1] as FieldAlias1, [Table].[Field 2] as FieldAlias2 ... from Table

    then queryying rs("FieldAlias1").value, that really should work...
    LVL 9

    Expert Comment

    oops that should obviously say....

    for t=0 to rs.fields.count -1
    reponse.write "<br>"  & rs(t).name & "<br>"
    next t
    LVL 9

    Expert Comment

    I feel that i had offered most contribution but @ 25 points, really not that fussed.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Suggested Solutions

    INTRODUCTION We all know how to code. But at times you simply want to insert a common code block into your existing code and amend it as per your requirements. This tool not only saves you time but also saves you the pain of typing it all out aga…
    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now