SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2000
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    variables with sQL in ASP

    Hi,
    How do I use a variable in an SQL statement for ASP?

    What I want to do is pass a querystring to a page then Select the programID in the SQL statement.

    Here is the code and the variable is id (the last value at the end):

    rs2.Open "Select * FROM program, platformlink, platform WHERE program.programID = platformlink.programID AND platform.platformID = platformlink.platformid AND program.programID = 'id' ", objConn

    By the Way, id = 1 if that helps and here is the error message I get:
    Microsoft OLE DB Provider for ODBC Drivers error '80040e07'

    [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.

    I tried single, double and no quotes. Please help.
    Thanks.

  2. #2
    SitePoint Wizard big_al's Avatar
    Join Date
    May 2000
    Location
    Victoria, Australia
    Posts
    1,661
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To include variables you use '"& Somthing &"' for a string and "& Somthing &" for an integer.

    Your data type mismatch means that you where trying to compare an integer field with a string value or vice versa. You got this error because you had ID = '1' this means it's string ID = 1 would be an integer.

    Hope that helps
    .NET Code Monkey

  3. #3
    SitePoint Zealot
    Join Date
    Oct 1999
    Location
    France
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just to clarify big_al's reply: your statement should look like this ...

    "Select * FROM program, platformlink, platform WHERE program.programID = platformlink.programID AND platform.platformID = platformlink.platformid AND program.programID = " & id

    assuming id is numeric. If it was a string, you would need:

    "Select * FROM program, platformlink, platform WHERE program.programID = platformlink.programID AND platform.platformID = platformlink.platformid AND program.programID = '" & id & "'"

    HTH
    --
    Veronica Yuill
    Archetype IT


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
  •