Data type mismatch in criteria expression.

V

vazperen

I am very new to databases. I am getting the following error:



Error Type:

Microsoft OLE DB Provider for ODBC Drivers (0x80040E07)

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

/resultsadv.asp, line 45





Browser Type:

Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; Roadrunner; .NET
CLR 1.1.4322)



Page:

POST 73 bytes to /resultsadv.asp



POST Data:

type=%25&minyear=1951&maxyear=2003&minprice=0&maxprice=1000&Submit=Sear-
ch







This is the code:



Dim rsSearch__varType

rsSearch__varType = "%"

If (Request.Form("type") <> "") Then

rsSearch__varType = Request.Form("type")

End If

%>

<%

Dim rsSearch__varStartPrice

rsSearch__varStartPrice = "1"

If (Request.Form("minprice") <> "") Then

rsSearch__varStartPrice = Request.Form("minprice")

End If

%>

<%

Dim rsSearch__varEndPrice

rsSearch__varEndPrice = "1000000"

If (Request.Form("maxprice") <> "") Then

rsSearch__varEndPrice = Request.Form("maxprice")

End If

%>

<%

Dim rsSearch__varStartYear

rsSearch__varStartYear = "1800"

If (Request.Form("minyear") <> "") Then

rsSearch__varStartYear = Request.Form("minyear")

End If

%>

<%

Dim rsSearch__varEndYear

rsSearch__varEndYear = "2003"

If (Request.Form("maxyear") <> "") Then

rsSearch__varEndYear = Request.Form("maxyear")

End If

%>

<%

set rsSearch = Server.CreateObject("ADODB.Recordset")

rsSearch.ActiveConnection = MM_classifieds_STRING

rsSearch.Source = "SELECT * FROM ADS,AD_IMAGES,CATS,SUBS, TYPES WHERE
AD_APPROVED = 1 AND ADS.AD_ID=AD_IMAGES.AD_ID AND CATS.CAT_ID LIKE
ADS.CAT_ID AND SUBS.SUB_ID LIKE ADS.SUB_ID AND AD_EXPIRED > DATE() AND
ADS.TYPE_ID=TYPES.TYPE_ID AND TYPE_NAME like '" +
Replace(rsSearch__varType, "'", "''") + "' AND AD_PRICE BETWEEN " +
Replace(rsSearch__varStartPrice, "'", "''") + " AND " +
Replace(rsSearch__varEndPrice, "'", "''") + " AND YEAR BETWEEN " +
Replace(rsSearch__varStartYear, "'", "''") + " AND " +
Replace(rsSearch__varEndYear, "'", "''") + " ORDER BY CAT_NAME ASC"

rsSearch.CursorType = 0

rsSearch.CursorLocation = 2

rsSearch.LockType = 3

rsSearch.Open()

rsSearch_numRows = 0





I am doing a search that includes several fields sych as model, year,
and price. I do not know what's wrong.



Help!
 
G

GVaught

All ASP variables are variant datatypes. You are passing the variant results
into the Access database and a field or several fields within Access may be
currency, date, Number or String. You need to insure that you pass each
variant data entered from a form into its appropriate Access data type
counterpart. Therefore, Date values should be declared as CDate; String
values declared as CStr; Numbers could be declared as CLng, CInt etc. You
define these at the time you issue an Insert statements.

Example:

CStr(Request.Form("s2_optService")) & "'"
CLng(varControlNo)
CLng(Request.Form("s2_lngPieceCnt"))
CDate(Request.Form("s2_StartDate"))

Hope this helps....

PS. A good book to buy is from Wrox Press "Beginning ASP Databases". It is
my Bible for database and ASP.

vazperen said:
I am very new to databases. I am getting the following error:



Error Type:

Microsoft OLE DB Provider for ODBC Drivers (0x80040E07)

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

/resultsadv.asp, line 45





Browser Type:

Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; Roadrunner; .NET
CLR 1.1.4322)



Page:

POST 73 bytes to /resultsadv.asp



POST Data:

type=%25&minyear=1951&maxyear=2003&minprice=0&maxprice=1000&Submit=Sear-
ch







This is the code:



Dim rsSearch__varType

rsSearch__varType = "%"

If (Request.Form("type") <> "") Then

rsSearch__varType = Request.Form("type")

End If

%>

<%

Dim rsSearch__varStartPrice

rsSearch__varStartPrice = "1"

If (Request.Form("minprice") <> "") Then

rsSearch__varStartPrice = Request.Form("minprice")

End If

%>

<%

Dim rsSearch__varEndPrice

rsSearch__varEndPrice = "1000000"

If (Request.Form("maxprice") <> "") Then

rsSearch__varEndPrice = Request.Form("maxprice")

End If

%>

<%

Dim rsSearch__varStartYear

rsSearch__varStartYear = "1800"

If (Request.Form("minyear") <> "") Then

rsSearch__varStartYear = Request.Form("minyear")

End If

%>

<%

Dim rsSearch__varEndYear

rsSearch__varEndYear = "2003"

If (Request.Form("maxyear") <> "") Then

rsSearch__varEndYear = Request.Form("maxyear")

End If

%>

<%

set rsSearch = Server.CreateObject("ADODB.Recordset")

rsSearch.ActiveConnection = MM_classifieds_STRING

rsSearch.Source = "SELECT * FROM ADS,AD_IMAGES,CATS,SUBS, TYPES WHERE
AD_APPROVED = 1 AND ADS.AD_ID=AD_IMAGES.AD_ID AND CATS.CAT_ID LIKE
ADS.CAT_ID AND SUBS.SUB_ID LIKE ADS.SUB_ID AND AD_EXPIRED > DATE() AND
ADS.TYPE_ID=TYPES.TYPE_ID AND TYPE_NAME like '" +
Replace(rsSearch__varType, "'", "''") + "' AND AD_PRICE BETWEEN " +
Replace(rsSearch__varStartPrice, "'", "''") + " AND " +
Replace(rsSearch__varEndPrice, "'", "''") + " AND YEAR BETWEEN " +
Replace(rsSearch__varStartYear, "'", "''") + " AND " +
Replace(rsSearch__varEndYear, "'", "''") + " ORDER BY CAT_NAME ASC"

rsSearch.CursorType = 0

rsSearch.CursorLocation = 2

rsSearch.LockType = 3

rsSearch.Open()

rsSearch_numRows = 0





I am doing a search that includes several fields sych as model, year,
and price. I do not know what's wrong.



Help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top