SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru davedibiase's Avatar
    Join Date
    Aug 2001
    Location
    Toronto, Canada
    Posts
    829
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Selecting data with Autonumber in Access...

    I have a line of code in my script that looks like this:

    Set User = objDBCon.Execute("SELECT * FROM tblsUsers WHERE ID = '" & request.form("user") & "'")

    This gives me an error of data type not the same. Anyone know what the problem might be?
    ||Dave Di Biase||
    ----------------------------------
    "There are 2 secrets in life. 1) Never say everything you know."
    GFXWARS - The ultimate graphics battle!

  2. #2
    SitePoint Enthusiast PeteWJ's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would imagine it's because an autonumber in Access is a numeric field and you are surrounding the value in single quotes. Try:

    Set User = objDBCon.Execute("SELECT * FROM tblsUsers WHERE ID = " & request.form("user"))

    And it also might be a good idea, if you are not doing it already, to check that request.form("user") is a number before including it in the SQL.

    Hope that that sheds some light!

    Pete

  3. #3
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,121
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Well spotted, this would be better coding:

    [vbs]
    tuser=CInt(request.form("user"))
    if isNumeric(tuser) then
    Set User = objDBCon.Execute("SELECT * FROM tblsUsers WHERE ID = " & tuser)
    end if
    [/vbs]
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  4. #4
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,254
    Mentioned
    113 Post(s)
    Tagged
    1 Thread(s)
    Uhmmm....won't cint spit if the field isn't numeric?

    Wouldn't THIS be better?
    [vbs]
    tuser=request.form("user")
    if isNumeric(tuser) then
    Set User = objDBCon.Execute("SELECT * FROM tblsUsers WHERE ID = " & CInt(tuser))
    end if
    [/vbs]
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style

  5. #5
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,121
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Totally... I was actually unsure so I figured I'd post and get the correction if I was wrong Thanx Dave
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •