注册 登录
编程论坛 ASP技术论坛

asp站内搜索问题,各位大大进来帮帮忙看下吧,谢谢了

zhuxiaobin 发布于 2010-06-05 13:38, 436 次点击
如题,我的数据库是adbook.mdb
里面内容有管理员和通讯录两个表单,其中用的通讯录格式是
ID   df   姓名 性别 职务 内线 电话 部门
我的coon.asp代码是
<%  
dim db,conn,connstr
db="adbook.mdb"
set Conn = server.CreateObject("ADODB.Connection")
connstr="provider=microsoft.jet.oledb.4.0;data source="& server.MapPath(""&db&"")
conn.Open connstr

%>

,我的index.asp里面的搜索代码是
<form name="form1" method="post" action="search.asp">
          <label><input type="text" name="textfield">
         </label><label><select name="select">
           <option value="df">地方</option>
           <option value="姓名">姓名</option>
           <option value="职务">职务</option>
           <option value="部门">部门</option>
           <option value="内线">短号</option>
           <option value="电话">电话</option>
         </select>
         </label>
                         <label>
                         <input type="submit" name="Submit" value="提交">
                        
                         </label>
       </form>
最后我里面search.asp的代码为
<!--#include file="conn.asp" --><title>search</title>  
这是您搜索到的结果:
<table width="100%" border="0" cellspacing="0" cellpadding="0">
   <tr>
     <td>地方</td>
     <td>姓名</td>
     <td>职务</td>
     <td>部门</td>
     <td>短号</td>
     <td>电话</td>
   </tr>
<%
key=request("textfield") '获取搜索的关键字
kind=request("select")    '获取搜索的类别

str="select * from [通讯录] where 1=1 "
if kind<>"" then  
str=str&" and "&kind&" like '%" & key & "%'"  
end if
set searchrs=server.createobject("adodb.recordset")
searchrs.open str,conn,1,1
     if not searchrs.eof then
     while not searchrs.eof
%>
   <tr>
     <td> <%=searchrs("df")%></td>
     <td> <%=searchrs("姓名")%></td>
     <td> <%=searchrs("职务")%></td>
     <td> <%=searchrs("部门")%></td>
     <td> <%=searchrs("内线")%></td>
     <td> <%=searchrs("电话")%></td>
   </tr>
<%
        searchrs.movenext
     wend

end if
searchrs.close  
set searchrs=nothing

%>
</table>
搜索之后出现错误
FROM 子句语法错误。

\search.asp, line 21
21行是searchrs.open str,conn,1,1
还有乱码字体
请问怎么解决?作为asp爱好者,谢谢各位了
4 回复
#2
yms1232010-06-05 14:00
SQL语句错误,检查一下SQL语句生成的是否正确。
#3
zhuxiaobin2010-06-05 14:33
回复 2楼 yms123
具体点好么,哪一段出错了,谢谢斑竹大大了
#4
yms1232010-06-05 14:38
key=request("textfield") '获取搜索的关键字
kind=request("select")    '获取搜索的类别

str="select * from [通讯录] where 1=1 "
if kind<>"" then  
str=str&" and "&kind&" like '%" & key & "%'"  
end if
response.write str'这里输出一下sql语句看看哪里出错。
就是这个地方,你用的分页搜索?
#5
zhuxiaobin2010-06-05 14:46
回复 4楼 yms123
是的,我用的分页搜索的
1