Results 1 to 7 of 7
  1. #1
    Join Date
    May 2004
    Posts
    6

    Unanswered: Queries and Session Variables

    Hello,

    Can session variables be used in a query somehow? I my users to be able to click on a link, and from there the query would search the database for the value stored in the variable, (their username, for example), and then display those results. I don't want the users to have to click on a submit button or anything, just automatically search the database for their username via the session variable....or does anybody have an alternate suggestion?

    Thanks

  2. #2
    Join Date
    Apr 2004
    Posts
    50
    If you want to search a database on the server you need to send request to the server, hence your visitors have to click a button or link to trigger the search.

    You can use Session vars in your queries like this:

    Code:
    sSQL = "SELECT * FROM Users WHERE ID = " & Session("UserID")

  3. #3
    Join Date
    May 2004
    Posts
    6
    That gives me this error message:

    Microsoft JET Database Engine error '80040e14'

    Syntax error (missing operator) in query expression '='.

    /mygrade_interface/Results/grades.asp, line 18

  4. #4
    Join Date
    Apr 2004
    Posts
    50

  5. #5
    Join Date
    May 2004
    Posts
    6
    That's what I originally thought, but if I do this:
    Code:
    <%=Session(appName&"UserName")%>
    It will write that value to the page just fine. Any other ideas?

    Thanks

  6. #6
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    so you code currently looks like this...
    Code:
    sSQL = "SELECT * FROM Users WHERE ID = " & Session(appName&"UserName")
    Yes?

  7. #7
    Join Date
    May 2004
    Posts
    6
    I modified the code to look like this and now it works:

    Code:
    <%
    Dim VarSession
    VarSession = Session(appName&"UserName")
    strQuery = "SELECT * FROM Results Where StudentID = '" & VarSession & "' ORDER BY StudentLastName ASC,StudentFirstName ASC"
    Set rsGradeData = Conn.Execute(strQuery)
    If Not rsGradeData.BOF Then
    %>

Posting Permissions

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