Retrieving data from SQL through variables

Posted on 2009-02-16
Last Modified: 2012-05-06
Hi all,

I can't seem tp figure out this error message saying "Item cannot be found in the collection corresponding to the requested name or ordinal."

Normally i would use:
sData = sData & Chr(34) & "" & (rsGetData.Fields.Item("MYFIELDHERE").Value) & "" & Chr(34) & ","

But beucase all the fields are in an array which i am looping round, i am trying to do this:
sData = sData & Chr(34) & "" & (rsGetData.Fields.Item(myArray(i)).Value) & "" & Chr(34) & ","

But i am getting the error message "Item cannot be found in the collection corresponding to the requested name or ordinal.". I have checked each field and it is deffinatly in the select statement. There is no room for a typo as it is all from the database.

Anyone know how i can edit the below code to make it work? Not sure if i'm missing anything?

Thanks in advance!
sData = sData & Chr(34) & "" & (rsGetData.Fields.Item(myArray(i)).Value) & "" & Chr(34) & ","

Open in new window

Question by:previewservices

    Author Comment

    Just changed to code so i to see the fields that is outputing.

    sData = sData & Chr(34) & " (rsGetData.Fields.Item(" & myArray(i) & ").Value) & " & Chr(34) & ","      
    SELECT imagename, doctab.text1, doctab.text2, doctab.text27, doctab.date1, doctab.text3, doctab.text4, doctab.text5, doctab.text6, doctab.text7, doctab.text8, doctab.text9, doctab.text28, doctab.text10, doctab.text11, doctab.text12, doctab.text29, doctab.text13, doctab.text14, doctab.text15, doctab.text16, doctab.text17, doctab.text18, doctab.text19, doctab.text20, doctab.text21, doctab.text22, doctab.text23, doctab.text24, doctab.text25, doctab.text26 from doctab where doctab.text4='MR'
    " (rsGetData.Fields.Item(imagename).Value) & "," (rsGetData.Fields.Item(doctab.text1).Value) & "," (rsGetData.Fields.Item(doctab.text2).Value) & "," (rsGetData.Fields.Item(doctab.text27).Value) & "," (rsGetData.Fields.Item(doctab.date1).Value) & "," (rsGetData.Fields.Item(doctab.text3).Value) & "," (rsGetData.Fields.Item(doctab.text4).Value) & "," (rsGetData.Fields.Item(doctab.text5).Value) & "," (rsGetData.Fields.Item(doctab.text6).Value) & "," (rsGetData.Fields.Item(doctab.text7).Value) & "," (rsGetData.Fields.Item(doctab.text8).Value) & "," (rsGetData.Fields.Item(doctab.text9).Value) & "," (rsGetData.Fields.Item(doctab.text28).Value) & "," (rsGetData.Fields.Item(doctab.text10).Value) & "," (rsGetData.Fields.Item(doctab.text11).Value) & "," (rsGetData.Fields.Item(doctab.text12).Value) & "," (rsGetData.Fields.Item(doctab.text29).Value) & "," (rsGetData.Fields.Item(doctab.text13).Value) & "," (rsGetData.Fields.Item(doctab.text14).Value) & "," (rsGetData.Fields.Item(doctab.text15).Value) & "," (rsGetData.Fields.Item(doctab.text16).Value) & "," (rsGetData.Fields.Item(doctab.text17).Value) & "," (rsGetData.Fields.Item(doctab.text18).Value) & "," (rsGetData.Fields.Item(doctab.text19).Value) & "," (rsGetData.Fields.Item(doctab.text20).Value) & "," (rsGetData.Fields.Item(doctab.text21).Value) & "," (rsGetData.Fields.Item(doctab.text22).Value) & "," (rsGetData.Fields.Item(doctab.text23).Value) & "," (rsGetData.Fields.Item(doctab.text24).Value) & "," (rsGetData.Fields.Item(doctab.text25).Value) & "," (rsGetData.Fields.Item(doctab.text26).Value) & ",

    Open in new window


    Accepted Solution

    Figured it. it was outputing "tablename.fieldname" when asp only supports "fieldname"

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    Suggested Solutions

    Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
    This demonstration started out as a follow up to some recently posted questions on the subject of logging in: and…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    734 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

    22 Experts available now in Live!

    Get 1:1 Help Now