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!

Storing field names in a recordset 1

Status
Not open for further replies.

RichardHayes

Programmer
May 1, 2002
28
GB
I have stored a number of field names in a recordset which I want to use to retrieve the data from a different recordset. An excerpt from the code is as follows:

Response.Write(&quot;<td>&quot; & rsRenewals(rsFieldNames(&quot;FieldName&quot;)) & &quot;</td>&quot;)

Which returns the error of

ADODB.Recordset error '800a0cc1'
Item cannot be found in the collection corresponding to the requested name or ordinal.

I know that I have correctly named the fields in rsFieldNames because I copied them directly from the table design.

Any help would be much appreciated.


 
If it's ado you should be able to do something like:

for i = 0 to rsRenewals.Fields.Count -1
msgbox rsRenewals.Fields(i).Name
next

you'll then get a list of all the fieldnames - you should be able to check to see if your fieldnames agree with what's in your table.

Hope this helps...
 
This looks insane, but try it first then get back to us either way. Change:
Code:
Response.Write(&quot;<td>&quot; & rsRenewals(rsFieldNames(&quot;FieldName&quot;)) & &quot;</td>&quot;)
To:
Code:
Response.Write(&quot;<td>&quot; & rsRenewals(CStr(rsFieldNames(&quot;FieldName&quot;))) & &quot;</td>&quot;)
It is quick to try, and might solve your problem even though it doesn't look like it could help.
 
I got it to work by putting the field name into a string first, and then using the string as follows:

strFieldName = rsFieldNames(&quot;FieldName&quot;)
Response.Write(&quot;<td>&quot; & rsRenewals(strFieldName) & &quot;</td>&quot;)

Many thanks for your help and comments.
 
I'll bet the CStr( ) would have done the trick too.

I've run into this before with stuff returned by ADO. I'll have to take a closer look. My suspicion is that the stuff (like the field name) comes back as either a NUL-delimited C-style string or a byte array. VBScript can't handle either of these natively but can coerce them to string values when properly... motivated.

Weird as it sounds, even putting &quot;extra&quot; parentheses around it might have done the trick:
Code:
Response.Write(&quot;<td>&quot; & rsRenewals((rsFieldNames(&quot;FieldName&quot;))) & &quot;</td>&quot;)
Now I always do explicit type conversions on anything I get back from ADO: CStr( ), CLng( ), etc. Saves on the debugging frustration.
 
Follow-up to previous comments...

Well I tested it, and just putting in the parentheses doesn't do the trick. You have to CStr( ) the value that is returned.

I'm still curious about the actual &quot;string&quot; that comes back from the field, but I wasn't able to dig it out with VBScript.
 
Many thanks for your investigations, that is very interesting indeed, I did not know that about returning values from ADO.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top