Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Data type mismatch in criteria expression
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Data type mismatch in criteria expression

 Post Reply Post Reply Page  12>
Author
twooly View Drop Down
Groupie
Groupie


Joined: 24 September 2003
Status: Offline
Points: 64
Post Options Post Options   Thanks (0) Thanks(0)   Quote twooly Quote  Post ReplyReply Direct Link To This Post Topic: Data type mismatch in criteria expression
    Posted: 24 September 2003 at 6:02pm

I am trying to create a script to view/edit a profile.  I can login and pass session variables between pages but I am getting this error

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

/viewprofile.asp, line 54

If I comment things out I can see the SQL string and that is correct.  I can also see the userID variable too just fine.

PS line 54 is "rsViewProfile.Open strSQL, adoCon"

 

Here is the code

<%
'Dimension Variables
Dim strUserName 'Holds the name of the user
Dim userID
Dim adoCon         'Holds the Database Connection Object
Dim rsViewProfile   'Holds the recordset for the records in the database
Dim strSQL          'Holds the SQL query to query the database

'Get the users name passed from the previous page
strUserName = Session("userName")

userID = Session("userID")


'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("toddwoolums_site.mdb")

'Create an ADO recordset object
Set rsViewProfile = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT firstname FROM tblUsers WHERE ID ='" & userID & "'"

'Open the recordset with the SQL query
rsViewProfile.Open strSQL, adoCon


If NOT rsViewProfile.EOF Then

 Response.Write ("<br>")
     Response.Write (rsViewProfile("firstname"))
 
     Response.Write ("<br>")
    
     Response.Write ("<br>")
End If

'Reset server objects
rsViewProfile.Close
Set rsViewProfile = Nothing
Set adoCon = Nothing
%>

sql string <% = strSQL %>
 Your user id is <% =userID %>

Back to Top
Gullanian View Drop Down
Senior Member
Senior Member
Avatar

Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gullanian Quote  Post ReplyReply Direct Link To This Post Posted: 24 September 2003 at 6:09pm

Try changing:

strSQL = "SELECT firstname FROM tblUsers WHERE ID ='" & userID & "'"

To

strSQL = "SELECT firstname FROM tblUsers WHERE ID =" & userID

Back to Top
twooly View Drop Down
Groupie
Groupie


Joined: 24 September 2003
Status: Offline
Points: 64
Post Options Post Options   Thanks (0) Thanks(0)   Quote twooly Quote  Post ReplyReply Direct Link To This Post Posted: 24 September 2003 at 9:21pm

Now I get this

 

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Microsoft Access Driver] Syntax error in string in query expression 'ID ='1'.

/viewprofile.asp, line 54

Back to Top
twooly View Drop Down
Groupie
Groupie


Joined: 24 September 2003
Status: Offline
Points: 64
Post Options Post Options   Thanks (0) Thanks(0)   Quote twooly Quote  Post ReplyReply Direct Link To This Post Posted: 24 September 2003 at 9:22pm
Never mind spoke too soon.  Works now
Back to Top
hassack View Drop Down
Newbie
Newbie
Avatar

Joined: 23 October 2003
Location: Argentina
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote hassack Quote  Post ReplyReply Direct Link To This Post Posted: 23 October 2003 at 12:51pm
How twooly??? i have the same problem..!!!!
Back to Top
KCWebMonkey View Drop Down
Senior Member
Senior Member
Avatar
Go Chiefs!

Joined: 21 June 2002
Status: Offline
Points: 1319
Post Options Post Options   Thanks (0) Thanks(0)   Quote KCWebMonkey Quote  Post ReplyReply Direct Link To This Post Posted: 23 October 2003 at 1:00pm
umm, then do the same solution...
Back to Top
hassack View Drop Down
Newbie
Newbie
Avatar

Joined: 23 October 2003
Location: Argentina
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote hassack Quote  Post ReplyReply Direct Link To This Post Posted: 23 October 2003 at 4:51pm
I think may be he has another solution ... , i have the same second problem when used the first example, but no problem i can fix right now
Back to Top
twooly View Drop Down
Groupie
Groupie


Joined: 24 September 2003
Status: Offline
Points: 64
Post Options Post Options   Thanks (0) Thanks(0)   Quote twooly Quote  Post ReplyReply Direct Link To This Post Posted: 24 October 2003 at 9:01am

Just use the sql string given above

strSQL = "SELECT firstname FROM tblUsers WHERE ID =" & userID

Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.