If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Queries and Session Variables

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-29-04, 23:46
jmurrayhead jmurrayhead is offline
Registered User
 
Join Date: May 2004
Posts: 6
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
Reply With Quote
  #2 (permalink)  
Old 05-30-04, 18:25
ASP-Hosting.ca ASP-Hosting.ca is offline
Registered User
 
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")
Reply With Quote
  #3 (permalink)  
Old 05-30-04, 20:14
jmurrayhead jmurrayhead is offline
Registered User
 
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
Reply With Quote
  #4 (permalink)  
Old 05-30-04, 20:33
ASP-Hosting.ca ASP-Hosting.ca is offline
Registered User
 
Join Date: Apr 2004
Posts: 50
This means your Session variable is empty.
Reply With Quote
  #5 (permalink)  
Old 05-30-04, 20:53
jmurrayhead jmurrayhead is offline
Registered User
 
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
Reply With Quote
  #6 (permalink)  
Old 05-30-04, 22:37
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
so you code currently looks like this...
Code:
sSQL = "SELECT * FROM Users WHERE ID = " & Session(appName&"UserName")
Yes?
Reply With Quote
  #7 (permalink)  
Old 05-31-04, 00:05
jmurrayhead jmurrayhead is offline
Registered User
 
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
%>
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On