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 > Syntax error (missing operator) in query expression

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-24-04, 11:09
breeze76 breeze76 is offline
Registered User
 
Join Date: Apr 2004
Posts: 75
Exclamation Syntax error (missing operator) in query expression

Here is my sql statement:
sql = "SELECT CASE_NAMES.ID, CASE_NAMES.CASE_NAME, CASE_USERS.CaseID, CASE_USERS.UserName FROM CASE_NAMES INNER JOIN CASE_USERS ON CASE_NAMES.ID = CASE_USERS.CaseID WHERE CASE_USERS.UserName = " & strID

Here is the error I get:
Error Type:
Microsoft JET Database Engine (0x80040E14)
Syntax error (missing operator) in query expression 'CASE_USERS.UserName = Randall S. Acree'.
/extended_user_info.asp, line 84

Here is line 84:
objrs.Open sql, Myconn

I am lost, I have been working on this for two days now.. any suggestions PLEASE!..

Thanks.
Reply With Quote
  #2 (permalink)  
Old 10-24-04, 19:26
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
you need to wrap your string parameters in quotes to be able to do the search
Code:
sql = "SELECT CASE_NAMES.ID, CASE_NAMES.CASE_NAME, CASE_USERS.CaseID, CASE_USERS.UserName FROM CASE_NAMES INNER JOIN CASE_USERS ON CASE_NAMES.ID = CASE_USERS.CaseID WHERE CASE_USERS.UserName = '" & strID & "'"
Reply With Quote
  #3 (permalink)  
Old 10-24-04, 20:06
breeze76 breeze76 is offline
Registered User
 
Join Date: Apr 2004
Posts: 75
ok, did that, now I get this error:
Error Type:
ADODB.Recordset (0x800A0E7D)
The connection cannot be used to perform this operation. It is either closed or invalid in this context.
/extended_user_info.asp, line 98

Here is line 98:
objrs.Open sql, Myconn

what should I look for now?

Thanks for your reply..
Reply With Quote
  #4 (permalink)  
Old 10-24-04, 20:10
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
well either you are not opening your connection or you are closing it before you use it or it is becoming invalid some how.

Do you want to attach the whole page and I'll have a look for you....
Reply With Quote
  #5 (permalink)  
Old 10-24-04, 20:23
breeze76 breeze76 is offline
Registered User
 
Join Date: Apr 2004
Posts: 75
Ok attached is the file.. hope you can help.. thanks...

The file name if extended_user_info.txt (.asp)
Attached Files
File Type: txt extended_user_info.txt (5.6 KB, 296 views)
Reply With Quote
  #6 (permalink)  
Old 10-24-04, 20:27
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
okie, you have these three commands to open the database
Code:
'Myconn.Open "driver={Microsoft Access Driver (*.mdb)};;dbq=C:\inetpub\database\USERNAMES_PASSWORDS.mdb"
'Myconn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "C:\inetpub\database\USERNAMES_PASSWORDS.mdb"
'Myconn.Open "DBQ=" & Server.Mappath("../database/USERNAMES_PASSWORDS.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};"
but they are all commented out so the database is never actually being opened.
Reply With Quote
  #7 (permalink)  
Old 10-24-04, 21:03
breeze76 breeze76 is offline
Registered User
 
Join Date: Apr 2004
Posts: 75
Sorry about that, I guess I was trying something else, but this is the one I try to use:
Myconn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "C:\inetpub\database\USERNAMES_PASSWORDS.mdb"

and here is the error:
Error Type:
Microsoft JET Database Engine (0x80040E07)
Data type mismatch in criteria expression.
/extended_user_info.asp, line 98

Line 98:
objrs.Open sql, Myconn

Now if I use this one:
Myconn.Open "driver={Microsoft Access Driver (*.mdb)};;dbq=C:\inetpub\database\USERNAMES_PASSWO RDS.mdb"

I get thie error:
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E07)
[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.
/extended_user_info.asp, line 98


Line 98 same as above..

I am lost..

Thanks
Reply With Quote
  #8 (permalink)  
Old 10-24-04, 21:06
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
can you do a response.write on the sql string so we can see exactly what is being sent to the database?
Reply With Quote
  #9 (permalink)  
Old 10-24-04, 21:20
breeze76 breeze76 is offline
Registered User
 
Join Date: Apr 2004
Posts: 75
OK here is the response write from what you told me to do to the string at the end:
SELECT CASE_NAMES.ID, CASE_NAMES.CASE_NAME, CASE_USERS.CaseID, CASE_USERS.UserName FROM CASE_NAMES INNER JOIN CASE_USERS ON CASE_NAMES.ID = CASE_USERS.CaseID WHERE CASE_USERS.UserName = 'Randall S. Acree'

I do not think this will work because of the single quotes..

Here is the response.write without the single quotes:
SELECT CASE_NAMES.ID, CASE_NAMES.CASE_NAME, CASE_USERS.CaseID, CASE_USERS.UserName FROM CASE_NAMES INNER JOIN CASE_USERS ON CASE_NAMES.ID = CASE_USERS.CaseID WHERE CASE_USERS.UserName = Randall S. Acree

But then if I do that, this is the error I get using this connection:
Myconn.Open "driver={Microsoft Access Driver (*.mdb)};;dbq=C:\inetpub\database\USERNAMES_PASSWO RDS.mdb"

Error:
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'CASE_USERS.UserName = Randall S. Acree'.
/extended_user_info.asp, line 98

Line 98:
objrs.Open sql, Myconn

Hope this helps...
Reply With Quote
  #10 (permalink)  
Old 10-24-04, 21:26
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
okie, I am assuming that Username is a string value. If it is then you need the quotes. No question at all..... it's a standard trap for young players.

now what could be a problem is the join in your statement. Are both of those fields of the same time? eg, both integers or longs. Otherwise you can't join on them.

Another test you can do is replace your sql with this...
Code:
SELECT CASE_NAMES.ID, CASE_NAMES.CASE_NAME FROM CASE_NAMES
.. and see if that works... if it does try this...
Code:
SELECT CASE_NAMES.ID, CASE_NAMES.CASE_NAME, CASE_USERS.CaseID, CASE_USERS.UserName FROM CASE_NAMES INNER JOIN CASE_USERS ON CASE_NAMES.ID = CASE_USERS.CaseID
if that executes without a problem then you have a conflict in your datatypes for your username field.
Reply With Quote
  #11 (permalink)  
Old 10-24-04, 21:46
breeze76 breeze76 is offline
Registered User
 
Join Date: Apr 2004
Posts: 75
With the first code:
SELECT CASE_NAMES.ID, CASE_NAMES.CASE_NAME FROM CASE_NAMES

with the second code:
SELECT CASE_NAMES.ID, CASE_NAMES.CASE_NAME, CASE_USERS.CaseID, CASE_USERS.UserName FROM CASE_NAMES INNER JOIN CASE_USERS ON CASE_NAMES.ID = CASE_USERS.CaseID

both write out for me, it is when I use the WHERE and the & str part that is gets all messed up..

Oh, all I did was a response.write on the two, did you want me to do anything else?

Thanks again for all your help, this has really been bugging me..
Reply With Quote
  #12 (permalink)  
Old 10-24-04, 21:51
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
As well as response.writing them can you execute then against the database? I need to see if those parts fo the query are correct.

Last edited by rokslide; 10-24-04 at 21:53.
Reply With Quote
  #13 (permalink)  
Old 10-24-04, 21:59
breeze76 breeze76 is offline
Registered User
 
Join Date: Apr 2004
Posts: 75
Both did ok, no errors...
Reply With Quote
  #14 (permalink)  
Old 10-24-04, 22:01
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
do you know how to execute sql directly against your access database? create a new query, don't add any tables, change the view to sql, paste in your code and then execute it and see what happens (this is with this bit of code - SELECT CASE_NAMES.ID, CASE_NAMES.CASE_NAME, CASE_USERS.CaseID, CASE_USERS.UserName FROM CASE_NAMES INNER JOIN CASE_USERS ON CASE_NAMES.ID = CASE_USERS.CaseID WHERE CASE_USERS.UserName = 'Randall S. Acree')
Reply With Quote
  #15 (permalink)  
Old 10-24-04, 22:20
breeze76 breeze76 is offline
Registered User
 
Join Date: Apr 2004
Posts: 75
it says:
Data type mismatch in criteria expression.

I got that sql from the DB I just tested it on..

If I do just the sql query with out teh WHERE part it show the table with the correct info just not the specific user since I am not doing the WHERE part..
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