Field name is valid, but getting an "Item cannot be found.." error

J

J. Muenchbourg

The field name 'articleid', which is an identity/primary key , is not
being recognized in my recordset as I get an "
Item cannot be found in the collection corresponding to the requested
name or ordinal" error with the following- the line number that the
error message points to is on my response.write for the
rsid("articleID") :


dim sqlid,rsid
sqlid = "SELECT max(ArticleID) from tblarticles"
Set rsid = Server.CreateObject("ADODB.Recordset")
rsid.Open sqlid,sqlc,3
response.write rsid("ArticleID")

???
Muench
 
W

WIlliam Morris

Two things to check: 1. is the connection valid, and state = 1? 2. Is the
recordset state = 1?
 
B

Bob Barrows

J. Muenchbourg said:
The field name 'articleid', which is an identity/primary key , is not
being recognized in my recordset as I get an "
Item cannot be found in the collection corresponding to the requested
name or ordinal" error with the following- the line number that the
error message points to is on my response.write for the
rsid("articleID") :


dim sqlid,rsid
sqlid = "SELECT max(ArticleID) from tblarticles"
Set rsid = Server.CreateObject("ADODB.Recordset")
rsid.Open sqlid,sqlc,3
response.write rsid("ArticleID")
The problem is that this query does not return a column with the name
ArticleID. It's returning the result of an expression. The column is getting
some default name. It may be "Expr1" which is what you would see as the
column title if you ran this query in Access.

You need to either:
a) refer to the column by its ordinal position: response.write rsid(0).value
or
b) Use a column alias:
sqlid = "SELECT max(ArticleID) As MaxArticleID from tblarticles"
....
response.write rsid("MaxArticleID")

I prefer a) myself.

HTH,
Bob Barrows
 
A

Aaron Bertrand [MVP]

Hmmm - that's what I said ... ;-)

The newsgroups were pretty wacky, I actually didn't see your response until
I reset my group...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top