Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query Problem with Access 97 Database via ASP

Status
Not open for further replies.

lyen

Computer
Aug 21, 2001
1
0
0
US
Hello All! I am having a query problem on a numeric value. I am using the Access 97 database. It comes up with the following error messages:

Microsoft JET Database Engine error '80040e07'

Data type mismatch in criteria expression.

/ds3select.asp, line 57

Please help! Thanks a million!

Below is the short script that I used:

<%
' Declare our variables... always good practice!
Dim strURL ' The URL of this page so the form will work
' no matter what this file is named.

Dim cnnSearch ' ADO connection
Dim rstSearch ' ADO recordset
Dim strDBPath ' path to our Access database (*.mdb) file

Dim strSQL ' The SQL Query we build on the fly
Dim strSearch ' The text being looked for

' Retreive the URL of this page from Server Variables
strURL = Request.ServerVariables(&quot;URL&quot;)

' Retreive the term being searched for. I'm doing it on
' the QS since that allows people to bookmark results.
' You could just as easily have used the form collection.
strSearch = Request.QueryString(&quot;search&quot;)

' Since I'm doing this all in one page I need to see if anyone
' has searched for something. If they have we hit the DB.
' O/W I just show the search form and quit.

%>
<p>Search our DS3 database by ECP number. (% returns all)</p>
<form action=&quot;<%= strURL %>&quot; method=&quot;get&quot;>
<input name=&quot;search&quot; value=&quot;<%= strSearch %>&quot; />
<input type=&quot;submit&quot; />
</form>
<p>[Try '176' for an example]</p>
<%
If strSearch <> &quot;&quot; Then
' MapPath of virtual database file path to a physical path.
' If you want you could hard code a physical path here.
strDBPath = Server.MapPath(&quot;/ds3/ds3.mdb&quot;)


' Create an ADO Connection to connect to the sample database.
' We're using OLE DB but you could just as easily use ODBC or a DSN.
Set cnnSearch = Server.CreateObject(&quot;ADODB.Connection&quot;)

' This line is for the Access sample database:
cnnSearch.Open &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; & strDBPath & &quot;;&quot;

' We're actually using SQL Server so we use this line instead:
' cnnSearch.Open Application(&quot;SQLConnString&quot;)

' Build our query based on the input.
strSQL = &quot;SELECT ecp, carrier, t1id &quot; _
& &quot;FROM b1cell_alpha &quot; _
& &quot;WHERE ecp = '%&quot; & Replace(strSearch, &quot;'&quot;, &quot;''&quot;) & &quot;%' &quot; _
& &quot;ORDER BY ecp;&quot;

' Execute our query using the connection object. It automatically
' creates and returns a recordset which we store in our variable.
Set rstSearch = cnnSearch.Execute(strSQL)

' Display a table of the data in the recordset. We loop through the
' recordset displaying the fields from the table and using MoveNext
' to increment to the next record. We stop when we reach EOF.
' For fun I'm combining some fields and showwing you can do more then
' just spit out the data in the form it is in in the table.
%>
<table border=&quot;1&quot;>
<tr>
<th>ECP</th>
<th>T1 Circuit ID</th>
</tr>
<%
Do While Not rstSearch.EOF
%>
<tr>
<td align=center><%= rstSearch.Fields(&quot;ecp&quot;).Value %></td>
<td align=center><%= rstSearch.Fields(&quot;t1id&quot;).Value %></td>
</tr>
<%

rstSearch.MoveNext
Loop
%>
</table>
<%
' Close our recordset and connection and dispose of the objects
rstSearch.Close
Set rstSearch = Nothing
cnnSearch.Close
Set cnnSearch = Nothing
End If

' That's all folks! See it's really not all that hard.
%>
 
Status
Not open for further replies.
Back
Top