How to pass a variable to a query?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tom Murphy
    New Member
    • Jan 2011
    • 5

    How to pass a variable to a query?

    I want to enter a url of the form "http://www...../index.htm?MC001 " and pass the "MC001" to a query string. The query string I have now is:
    Code:
     qry = "SELECT QRID, QRContent FROM " & tablename & WHERE QRID= '" & request.querystring() & "'"
    Why does this not work?
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    It doesn't work because you need to specify the variable to retrieve from the QueryString.

    Right now you have no variable name defined...which is your first problem.

    Your query string should look like
    Code:
    "http://www...../index.htm?idCode=MC001"
    Now you can retrieve "idCode" from the QueryString to get MC001:
    Code:
    Dim idCode As String = Request.QueryString("idCode")
    -Frinny

    Comment

    Working...