Forum Moderators: open

Message Too Old, No Replies

Data type mismatch in criteria expression.

Problem

         

Johny Favourite

3:58 pm on Mar 4, 2004 (gmt 0)

10+ Year Member



First off I hope this is the right forum to ask about stuff like this.

Second if I'm breaking any of the rules by posting variables that relate to my website I'm sorry!

Basically I have the following code:

[Code]
<% If Request.Querystring("ModelID") <> "" Then %>
<%metavar = request("ModelID")%>
<%'Response.Buffer = false%>
<%
'Create database connection object (Advanced Data Objects)
Set MyMetaConn = server.createobject("ADODB.connection")

MyMetaConn.Open session("dataconn")

Set RsMeta = server.createobject("ADODB.recordset")
Set RsMeta.activeconnection = MyMetaConn
'Define the source SQL code for the recordset

RsMeta.source = " SELECT Appliance.ModelID, Appliance.ModelNo, Manufacturer.Manufacturer "

RsMeta.source = RsMeta.source & " FROM Manufacturer INNER JOIN Appliance ON Manufacturer.ManufacturerCode = Appliance.ManufacturerCode "

RsMeta.source = RsMeta.source & "WHERE (((Appliance.ModelID)= '" & metavar & "') AND (Not (Appliance.Exclude)=Yes));"

RsMeta.open , , 1, 3

%>

<%Do While not RsMeta.EOF%>
Response write some stuff (Removed cos it might break rules)
<%RsMeta.MoveNext%>
<%Loop%>
<%RsMeta.Close%>
<%Else%>
Do Stuff
<%End If%>

Right that fails.

NOw I think that it's cos the field ModelID is an autonumber which is a Long Int and the bit i get from page.asp?modelid=****x is not. Any way round this?

Thanking you for you time!

korkus2000

6:43 pm on Mar 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you tried converting it?

<%metavar = CLng(request("ModelID"))%>

wackal

8:22 pm on Mar 4, 2004 (gmt 0)

10+ Year Member



you have single quotes around a numeric field. i think thats your problem. change the code as follows:

RsMeta.source = RsMeta.source & "WHERE (((Appliance.ModelID)= '" & metavar & "') AND (Not (Appliance.Exclude)=Yes));"

RsMeta.source = RsMeta.source & "WHERE (((Appliance.ModelID)= " & metavar & ") AND (Not (Appliance.Exclude)=Yes));"

Johny Favourite

10:17 am on Mar 5, 2004 (gmt 0)

10+ Year Member



Thanks guys!

I used:

[code]
<%
dim intUserID
intUserID = Request.QueryString("ModelID")
intUserID = CLng(intUserID)
' intUserID is now an integer.
%>
[\code]

to convert and that was still failing!

However as soon as I changed the quotes it sailed in.

Many Many Thanks!