Below is the code and the error I am getting. Can anyone tell me what I am doing wrong? I want this search page to be able to search the database based by client. Searching the table named "projects" field name "ProjectName" and display the results.
My error message is as follows:
Microsoft JET Database Engine error '80040e14'
Syntax error (missing operator) in query expression '[Projects].[ClientID]='.
/cs/login/search.asp, line 17
Code:
<html>
<head>
</head>
<body>
<%
dim conn, rs, sql, intTelephone, intMobile
set rs = Server.CreateObject ("ADODB.Recordset")
Set conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\mydata\Data.mdb;" & _
"Jet OLEDB:System Database=c:\mydata\Scur.mdw", _
"xx", "xxxxxxxx"
sql = "SELECT * FROM [Projects] WHERE [Projects].[ClientID]=" &Trim(session("myvar1"))
rs.open sql, conn
searchcriteria = Request.Form("searchcriteria")
search = Request("search")
strRowColor = "#ffffff"
submit = Request.Form("submit")
id = Trim(session("myvar1"))
%>
<h4>SEARCH</h4>
<form name="searchForm" action="search.asp" method="POST">
Search: <input name="searchcriteria" size="50" maxlength="50" value="<%=searchcriteria%><%=search%>">
<input type="submit" name="submit" value="Find">
</form>
<hr>
<%
If submit <> "" AND searchcriteria <> "" Then
strSQL = "SELECT ID, ProjectsName FROM tblProjects WHERE Title LIKE '%" & searchcriteria & "%' ORDER BY Title"
objRS.Open strSQL, objConn, 3 , 3
If objRS.EOF Then
Response.Write "There are no records that match your criteria."
objRS.Close
Else
Response.Write "Search found " & objRS.RecordCount & " record(s)"
%>
<table border="1">
<tr>
<th>ID</th>
<th>Title</th>
<th>Company</th>
</tr>
<%
Do While Not objRS.EOF
%>
<tr bgcolor="<%=strRowColor%>">
<td><a href="search.asp?search=<%=searchcriteria%>&id=<%=objRS("ID")%>"><%=objRS("ID")%></a> </td>
<td><%=objRS("Title")%> </td>
<td><%=objRS("Company")%> </td>
</tr>
<%
If strRowColor = "#ffffff" Then strRowColor = "#dddddd" Else strRowColor = "#ffffff"
objRS.MoveNext
Loop
Response.Write "</table>"
objRS.Close
End If
End If
If id <> "" AND search <> "" Then
strSQL="SELECT ID, Projects, Description FROM tblProjects WHERE ID=" & id & ";"
objRS.Open strSQL, objConn
Response.Write "<u>" & objRS("Title") & "</u> : " & objRS("Projects") & "<br>" & vbCrlf & _
"<p>Description: <br>" & vbCrlf & _
"<textarea borderline=""0"" disabled cols=""100"" rows=""5"">" & objRS("ProjectName") & "</textarea>" & vbCrlf & _
"</p>"
End If
%>
</body>
</html>
My error message is as follows:
Microsoft JET Database Engine error '80040e14'
Syntax error (missing operator) in query expression '[Projects].[ClientID]='.
/cs/login/search.asp, line 17
Code:
<html>
<head>
</head>
<body>
<%
dim conn, rs, sql, intTelephone, intMobile
set rs = Server.CreateObject ("ADODB.Recordset")
Set conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\mydata\Data.mdb;" & _
"Jet OLEDB:System Database=c:\mydata\Scur.mdw", _
"xx", "xxxxxxxx"
sql = "SELECT * FROM [Projects] WHERE [Projects].[ClientID]=" &Trim(session("myvar1"))
rs.open sql, conn
searchcriteria = Request.Form("searchcriteria")
search = Request("search")
strRowColor = "#ffffff"
submit = Request.Form("submit")
id = Trim(session("myvar1"))
%>
<h4>SEARCH</h4>
<form name="searchForm" action="search.asp" method="POST">
Search: <input name="searchcriteria" size="50" maxlength="50" value="<%=searchcriteria%><%=search%>">
<input type="submit" name="submit" value="Find">
</form>
<hr>
<%
If submit <> "" AND searchcriteria <> "" Then
strSQL = "SELECT ID, ProjectsName FROM tblProjects WHERE Title LIKE '%" & searchcriteria & "%' ORDER BY Title"
objRS.Open strSQL, objConn, 3 , 3
If objRS.EOF Then
Response.Write "There are no records that match your criteria."
objRS.Close
Else
Response.Write "Search found " & objRS.RecordCount & " record(s)"
%>
<table border="1">
<tr>
<th>ID</th>
<th>Title</th>
<th>Company</th>
</tr>
<%
Do While Not objRS.EOF
%>
<tr bgcolor="<%=strRowColor%>">
<td><a href="search.asp?search=<%=searchcriteria%>&id=<%=objRS("ID")%>"><%=objRS("ID")%></a> </td>
<td><%=objRS("Title")%> </td>
<td><%=objRS("Company")%> </td>
</tr>
<%
If strRowColor = "#ffffff" Then strRowColor = "#dddddd" Else strRowColor = "#ffffff"
objRS.MoveNext
Loop
Response.Write "</table>"
objRS.Close
End If
End If
If id <> "" AND search <> "" Then
strSQL="SELECT ID, Projects, Description FROM tblProjects WHERE ID=" & id & ";"
objRS.Open strSQL, objConn
Response.Write "<u>" & objRS("Title") & "</u> : " & objRS("Projects") & "<br>" & vbCrlf & _
"<p>Description: <br>" & vbCrlf & _
"<textarea borderline=""0"" disabled cols=""100"" rows=""5"">" & objRS("ProjectName") & "</textarea>" & vbCrlf & _
"</p>"
End If
%>
</body>
</html>