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

Discussion in 'ASP General' started by J. Muenchbourg, Sep 25, 2003.

  1. 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

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    J. Muenchbourg, Sep 25, 2003
    #1
    1. Advertising

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


    --
    William Morris
    Product Development, Seritas LLC


    "J. Muenchbourg" <> wrote in message
    news:#...
    > 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
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
     
    WIlliam Morris, Sep 25, 2003
    #2
    1. Advertising

  3. J. Muenchbourg

    Bob Barrows Guest

    J. Muenchbourg wrote:
    > 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
     
    Bob Barrows, Sep 25, 2003
    #3
  4. > sqlid = "SELECT max(ArticleID) from tblarticles"

    No, the /column/ name is not valid. Notice you did not ask for ArticleID
    here, you asked for max(ArticleID).

    http://www.aspfaq.com/2159
     
    Aaron Bertrand [MVP], Sep 26, 2003
    #4
  5. J. Muenchbourg

    Bob Barrows Guest

    Aaron Bertrand [MVP] wrote:
    >> sqlid = "SELECT max(ArticleID) from tblarticles"

    >
    > No, the /column/ name is not valid. Notice you did not ask for
    > ArticleID here, you asked for max(ArticleID).
    >
    > http://www.aspfaq.com/2159


    Hmmm - that's what I said ... ;-)
     
    Bob Barrows, Sep 26, 2003
    #5
  6. > Hmmm - that's what I said ... ;-)

    The newsgroups were pretty wacky, I actually didn't see your response until
    I reset my group...
     
    Aaron Bertrand [MVP], Sep 27, 2003
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Davis
    Replies:
    2
    Views:
    411
    Dave Anderson
    Aug 18, 2003
  2. CJM
    Replies:
    2
    Views:
    223
  3. Vinod
    Replies:
    4
    Views:
    1,022
    Patrice
    Feb 24, 2005
  4. Pavils Jurjans
    Replies:
    3
    Views:
    218
    Pavils Jurjans
    Mar 18, 2005
  5. Sound
    Replies:
    2
    Views:
    480
    Randy Webb
    Sep 28, 2006
Loading...

Share This Page