郁闷了一天~~总觉得没什么错误~~大家帮我看看,急~~

91jk 2004-12-25 08:53:14
我做了个搜索,数据库中有数据,我按照条件搜索,但是怎么老是有“没有符合您要求的记录”的提示啊?帮我看看啊`~~~
<%dim dbpath,rs,conn
dim fdkemu,mqcd,xssex,price,sql,pre,str
fdkemu=request("fdkemu")
mqcd=request("mqcd")
xssex=request("xssex")
price=request("price")

DbPath = SERVER.MapPath("../cnm/wuzifengloverongrong.mdb")
Set conn = Server.CreateObject("ADODB.Connection")
conn.open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DbPath
Set rs = Server.CreateObject("ADODB.Recordset")
'///////////////////////////////////////////////////////////////////////////////// 取得线路信息
if fdkemu=""and mqcd="" and xssex="" and price="" then
response.write"<script language='javascript'>"
response.write"alert('至少应该有一个查询条件!');"
response.write"history.go(-1);"
response.write"</script>"
response.end
else
sql="select fdkemu,mqcd,xssex,price from student where (id is null)"
if fdkemu<>"" then
sql=sql&"and fdkemu like '%"&fdkemu&"%' "
end if

if mqcd<>"" then
sql=sql&"and mqcd like '%"&mqcd&"%' "
end if
if xssex<>"" then
sql=sql&"and xssex like '%"&xssex&"%' "
end if

if price<>"" then
sql=sql&"and price like '%"&price&"%' "
end if
rs.open sql,conn,3,2
if rs.eof or rs.bof then
response.write"<script language='javascript'>"
response.write"alert('没有符合您要求的记录!');"
response.write"history.go(-1);"
response.write"</script>"
response.end
end if
end if
%>
...全文
171 24 打赏 收藏 转发到动态 举报
写回复
用AI写文章
24 条回复
切换为时间正序
请发表友善的回复…
发表回复
91jk 2004-12-25
  • 打赏
  • 举报
回复
感谢大家,感谢!!!
riyao 2004-12-25
  • 打赏
  • 举报
回复
有可能是数据字段的数据类型有误,,,

楼主可以把你的SQL语句拷贝到access中的查询中的SQL视图,然后根据你的具体输入赋值,看能不能查到值。。。能的话就不是SQL语句的错误了。。。看看别的了。。
xihasky 2004-12-25
  • 打赏
  • 举报
回复
总的来说两个问题,一个是参数接受,一个是sql生成的判断和读取字段问题
xihasky 2004-12-25
  • 打赏
  • 举报
回复
<% option explicit %>
<%
dim dbpath,rs,conn
dim fdkemu,mqcd,xssex,price,sql,pre,str,pages,records,currentpage,linenumber,line,keyword,px,p

'''根据第一个页面,可知如果什么也不选,会出现问题,所以用replace解决.
fdkemu=replace(request("fdkemu"),"科目","")
mqcd=replace(request("mqcd"),"程度","")
xssex=replace(request("xssex"),"性别","")
price=replace(request("price"),"接受价格","")

DbPath = SERVER.MapPath("data/wuzifengloverongrong.mdb")
Set conn = Server.CreateObject("ADODB.Connection")
conn.open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DbPath
Set rs = Server.CreateObject("ADODB.Recordset")
'///////////////////////////////////////////////////////////////////////////////// 取得线路信息
if fdkemu=" " and mqcd=" " and xssex=" " and price=" " then
response.write"<script language='javascript'>"
response.write"alert('至少应该有一个查询条件!');"
response.write"history.go(-1);"
response.write"</script>"
response.end
else

'''sql的判断有问题,读取的字段也少了.不过不赞成用*号,这样会延长查询时间
sql="select * from student where "
if fdkemu<>"" then
sql=sql&" fdkemu like '%"&fdkemu&"%' "
end if
if mqcd<>"" then
if fdkemu<>"" then
sql = sql & " and"
end if
sql=sql&" mqcd like '%"&mqcd&"%' "
end if
if xssex<>"" then
if fdkemu<>"" or mqcd<>"" then
sql = sql & " and"
end if
sql=sql&" xssex like '%"&xssex&"%' "
end if

if price<>"" then
if fdkemu<>"" or mqcd<>"" or xssex<>"" then
sql = sql & " and"
end if
sql=sql&" and price like '%"&price&"%' "
end if

'response.Write(sql)
'response.End()

rs.open sql,conn,3,2
if rs.eof and rs.bof then
response.write"<script language='javascript'>"
response.write"alert('没有符合您要求的记录!');"
response.write"history.go(-1);"
response.write"</script>"
response.end
end if

'分页程序
if str="" then
rs.PageSize=15
pages=rs.pagecount
records=rs.recordcount
currentpage=request("currentpage")
if currentpage="" or currentpage<1 then currentpage=1
currentpage=cint(currentpage)
if currentpage>pages then currentpage=pages
rs.absolutepage=currentpage
else
currentpage=1
records=0
pages=1
end if
end if
%>
<table width="760" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#DEF3EF">
<tr bgcolor="#6BBAE7">
<td bgcolor="#DEF3EF"><strong>以下是所有学生列表</strong></td>
</tr>
<tr bgcolor="#6BBAE7">
<td bgcolor="#DEF3EF"> <table width="100%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#DEF3EF">
<tr>
<td align="center" valign="middle" salign="center"><br> <table width="750" border="0" cellpadding="1" cellspacing="1" bgcolor="#000000">
<tr bgcolor="#6BBAE7">
<td width="53"> <div align="center">编号</div></td>
<td width="53"> <div align="center">性别</div></td>
<td width="102"> <div align="center">目前程度</div></td>
<td width="101"> <div align="center">辅导科目</div></td>
<td width="82"> <div align="center">老师专业</div></td>
<td width="123"> <div align="center">家庭住址</div></td>
<td width="102"> <div align="center">接受价格</div></td>
<td width="109"> <div align="center">详情</div></td>
</tr>
<%linenumber=rs.pagesize%>
<%do while (not rs.eof) and (line<linenumber)%>
<tr align="center" bgcolor="#6BBAE7">
<td height="21" bgcolor="#DEF3EF"><%=rs("id")%> <div align="center"></div></td>
<td bgcolor="#DEF3EF"><%=rs("xsname")%> <div align="center"></div></td>
<td bgcolor="#DEF3EF">
<% =rs("mqcd") %>
<div align="center"></div></td>
<td bgcolor="#DEF3EF">
<% =rs("fdkemu") %>
<div align="center"></div></td>
<td bgcolor="#DEF3EF">
<% =rs("lszhuanye") %>
<div align="center"></div></td>
<td bgcolor="#DEF3EF">
<% =rs("jtaddress") %>
<div align="center"></div></td>
<td bgcolor="#DEF3EF"> <div align="center">
<% =rs("price") %>
</div></td>
<td bgcolor="#DEF3EF"> <div align="center"><a href=javascript:winopen('read.asp?id=<%=rs("id")%>') )>查看详情</a></div></td>
</tr>
<%rs.movenext%>
<%line=line+1%>
<%loop%>
<tr align="right" bgcolor="#DEF3EF">
<td colspan="8"> <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="white">
<tr>
<td height="56" bgcolor="white"> <br>
您现在所在第<font color="blue"><%=currentpage%></font>页 供应信息共有<font color="blue">
<%=Records%> </font>条 <font size="2">每页显示</font><font color="blue">50</font>条
<%if currentpage>1 then%>
<font size="2"><a href="searchout.asp?currentpage=<%=currentpage-1%>&t1=<%=keyword%>&px=<%=px%>"><font size="2">[上一页]</font></a>
<%end if%>
<%if currentpage<pages then%>
<a href="searchout.asp?currentpage=<%=currentpage+1%>&t1=<%=keyword%>&px=<%=px%>">[下一页]</a>
<%end if%>
<%if currentpage>1 then%>
<a href="searchout.asp?currentpage=1&t1=<%=keyword%>&px=<%=px%>">[最首页]</a>
<%end if%>
<%if currentpage<pages then%>
<a href="searchout.asp?currentpage=<%=pages%>&t1=<%=keyword%>&px=<%=px%>">[最末页]</a>
<%end if%>
共有<font color="blue"><%=Pages%></font>页转到页码:[
<%for p=1 to pages%>
<a <%if currentpage=p then%> style="color:red" <%end if%> href="searchout.asp?currentpage=<%=p%>&t1=<%=keyword%>&px=<%=px%>"><%=p%></a>
<%if p/30=0 then%>
<%end if%>
<%next%>
]</font> </td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>
</html>
hxnet 2004-12-25
  • 打赏
  • 举报
回复
sql="select fdkemu,mqcd,xssex,price from student where "标识ID"<>-1 把下标放到第一个ID上
91jk 2004-12-25
  • 打赏
  • 举报
回复
seacrthout.asp

<% option explicit %>
<%
dim dbpath,rs,conn
dim fdkemu,mqcd,xssex,price,sql,pre,str,pages,records,currentpage,linenumber,line,keyword,px,p
fdkemu=trim(request("fdkemu"))
mqcd=trim(request("mqcd"))
xssex=trim(request("xssex"))
price=trim(request("price"))

DbPath = SERVER.MapPath("../cnm/wuzifengloverongrong.mdb")
Set conn = Server.CreateObject("ADODB.Connection")
conn.open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DbPath
Set rs = Server.CreateObject("ADODB.Recordset")
if fdkemu=" " and mqcd=" " and xssex=" " and price=" " then
response.write"<script language='javascript'>"
response.write"alert('至少应该有一个查询条件!');"
response.write"history.go(-1);"
response.write"</script>"
response.end
else
sql="select fdkemu,mqcd,xssex,price from student where 1=1"
if fdkemu<>"" then
sql=sql&" and fdkemu like '%"&fdkemu&"%' "
end if

if mqcd<>"" then
sql=sql&" and mqcd like '%"&mqcd&"%' "
end if
if xssex<>"" then
sql=sql&" and xssex like '%"&xssex&"%' "
end if

if price<>"" then
sql=sql&" and price like '%"&price&"%' "
end if

rs.open sql,conn,3,2
if rs.eof and rs.bof then
response.write"<script language='javascript'>"
response.write"alert('没有符合您要求的记录!');"
response.write"history.go(-1);"
response.write"</script>"
response.end
end if

'分页程序
if str="" then
rs.PageSize=15
pages=rs.pagecount
records=rs.recordcount
currentpage=request("currentpage")
if currentpage="" or currentpage<1 then currentpage=1
currentpage=cint(currentpage)
if currentpage>pages then currentpage=pages
rs.absolutepage=currentpage
else
currentpage=1
records=0
pages=1
end if
end if
%>
<table width="760" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#DEF3EF">
<tr bgcolor="#6BBAE7">
<td bgcolor="#DEF3EF"><strong>以下是所有学生列表</strong></td>
</tr>
<tr bgcolor="#6BBAE7">
<td bgcolor="#DEF3EF"> <table width="100%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#DEF3EF">
<tr>
<td align="center" valign="middle" salign="center"><br> <table width="750" border="0" cellpadding="1" cellspacing="1" bgcolor="#000000">
<tr bgcolor="#6BBAE7">
<td width="53"> <div align="center">编号</div></td>
<td width="53"> <div align="center">性别</div></td>
<td width="102"> <div align="center">目前程度</div></td>
<td width="101"> <div align="center">辅导科目</div></td>
<td width="82"> <div align="center">老师专业</div></td>
<td width="123"> <div align="center">家庭住址</div></td>
<td width="102"> <div align="center">接受价格</div></td>
<td width="109"> <div align="center">详情</div></td>
</tr>
<%linenumber=rs.pagesize%>
<%do while (not rs.eof) and (line<linenumber)%>
<tr align="center" bgcolor="#6BBAE7">
<td height="21" bgcolor="#DEF3EF"><%=rs("id")%> <div align="center"></div></td>
<td bgcolor="#DEF3EF"><%=rs("xsname")%> <div align="center"></div></td>
<td bgcolor="#DEF3EF">
<% =rs("mqcd") %>
<div align="center"></div></td>
<td bgcolor="#DEF3EF">
<% =rs("fdkemu") %>
<div align="center"></div></td>
<td bgcolor="#DEF3EF">
<% =rs("lszhuanye") %>
<div align="center"></div></td>
<td bgcolor="#DEF3EF">
<% =rs("jtaddress") %>
<div align="center"></div></td>
<td bgcolor="#DEF3EF"> <div align="center">
<% =rs("price") %>
</div></td>
<td bgcolor="#DEF3EF"> <div align="center"><a href=javascript:winopen('read.asp?id=<%=rs("id")%>') )>查看详情</a></div></td>
</tr>
<%rs.movenext%>
<%line=line+1%>
<%loop%>
<tr align="right" bgcolor="#DEF3EF">
<td colspan="8"> <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="white">
<tr>
<td height="56" bgcolor="white"> <br>
您现在所在第<font color="blue"><%=currentpage%></font>页 供应信息共有<font color="blue">
<%=Records%> </font>条 <font size="2">每页显示</font><font color="blue">50</font>条
<%if currentpage>1 then%>
<font size="2"><a href="searchout.asp?currentpage=<%=currentpage-1%>&t1=<%=keyword%>&px=<%=px%>"><font size="2">[上一页]</font></a>
<%end if%>
<%if currentpage<pages then%>
<a href="searchout.asp?currentpage=<%=currentpage+1%>&t1=<%=keyword%>&px=<%=px%>">[下一页]</a>
<%end if%>
<%if currentpage>1 then%>
<a href="searchout.asp?currentpage=1&t1=<%=keyword%>&px=<%=px%>">[最首页]</a>
<%end if%>
<%if currentpage<pages then%>
<a href="searchout.asp?currentpage=<%=pages%>&t1=<%=keyword%>&px=<%=px%>">[最末页]</a>
<%end if%>
共有<font color="blue"><%=Pages%></font>页转到页码:[
<%for p=1 to pages%>
<a <%if currentpage=p then%> style="color:red" <%end if%> href="searchout.asp?currentpage=<%=p%>&t1=<%=keyword%>&px=<%=px%>"><%=p%></a>
<%if p/30=0 then%>
<%end if%>
<%next%>
]</font> </td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>
</html>
91jk 2004-12-25
  • 打赏
  • 举报
回复
我把我2个文件都帖出来,大家帮我看看~~~~~~~~~~~我另外开个帖子加分~~~

search.asp
<table width="410" height="34%" border="0" align="center" cellpadding="3" cellspacing="0" bgcolor="e7e7e7">
<form action=seacrthout.asp method=post>
<tr>
<td width="90" height="36%">辅导科目</td>
<td width="103"><strong>
<select name="fdkemu" id="fdkemu">
<option>科目</option>
<option value="语文">语文</option>
<option value="数学">数学</option>
<option value="英语">英语</option>
<option value="物理">物理</option>
<option value="化学">化学</option>
<option value="电脑">电脑</option>
<option value="书法">书法</option>
<option value="音乐">音乐</option>
<option value="舞蹈">舞蹈</option>
<option value="吉他">吉他</option>
<option value="钢琴">钢琴</option>
<option value="作文">作文</option>
<option value="武术">武术</option>
<option value="其他">其他</option>
</select>
</strong></td>
<td width="76">目前程度</td>
<td width="141"><select name="mqcd" id="mqcd">
<option>程度</option>
<option value="幼儿">幼儿</option>
<option value="小学">小学</option>
<option value="初中">初中</option>
<option value="高中">高中</option>
<option value="成人`">成人</option>
<option value="其他">其他</option>
</select></td>
</tr>
<tr>
<td height="36%">学生性别:</td>
<td><select name="xssex" id="xssex">
<option>性别</option>
<option value="男生">男</option>
<option value="女生">女</option>
</select></td>
<td>接受价格</td>
<td><select name="price" id="price">
<option>接受价格</option>
<option value="10-15">10-15</option>
<option value="15-20">15-20</option>
<option value="20-25">20-25</option>
<option value="25-30">25-30</option>
<option value="30元以上">30元以上</option>
</select></td>
</tr>
<tr background="image/23.gif">
<td height="28%" colspan="4">
<div align="center">
<input type="submit" name="Submit" value="提交">
 
<input type="reset" name="Submit2" value="重置">
</div></td>
</tr>
</form>
</table>
plagyy 2004-12-25
  • 打赏
  • 举报
回复
rs.open sql,conn,3,2权限高于rs.open sql,conn,1,1,这个不会有错
yeno 2004-12-25
  • 打赏
  • 举报
回复
rs.open sql,conn,3,2 改成
rs.open sql,conn,1,1
yeno 2004-12-25
  • 打赏
  • 举报
回复
你每个And前都要加哦,除非字段在数据表中不存在,否则没可能报错的,楼主
plagyy 2004-12-25
  • 打赏
  • 举报
回复
if rs.eof or rs.bof then
改成if rs.eof and rs.bof then
看看
还不行就该成这样
sql="select fdkemu,mqcd,xssex,price from student where 1=1"
if fdkemu<>"" then
sql=sql&" and fdkemu like '%"&fdkemu&"%' "
end if

if mqcd<>"" then
sql=sql&" and mqcd like '%"&mqcd&"%' "
end if
if xssex<>"" then
sql=sql&" and xssex like '%"&xssex&"%' "
end if

if price<>"" then
sql=sql&" and price like '%"&price&"%' "
end if
91jk 2004-12-25
  • 打赏
  • 举报
回复


if fdkemu=""and mqcd="" and xssex="" and price="" then
response.write"<script language='javascript'>"
response.write"alert('至少应该有一个查询条件!');"
response.write"history.go(-1);"
response.write"</script>"
response.end
而且我什么条件都不选,它应该会弹出这样的提示啊?怎么就直接跳到后面了呢
popcode 2004-12-25
  • 打赏
  • 举报
回复
把sql语句打印出来看
91jk 2004-12-25
  • 打赏
  • 举报
回复
回复人: xihasky(xihasky) ( ) 信誉:100

我加你了呀~~
91jk 2004-12-25
  • 打赏
  • 举报
回复
: yeno(好好保护偶这只仅存的菜鸟(猎头网:HUNTER5156.COM)) ( ) 信誉:95

按照你的写法还是同样报错啊~~再帮我看看好不?
xihasky 2004-12-25
  • 打赏
  • 举报
回复
加我qq:93431391或msn:jl_xiao@hotmail.com我们一起来探讨,这里聊天不方便
yeno 2004-12-25
  • 打赏
  • 举报
回复
不写报错,你也不能那样写呀,呵呵

sql="select fdkemu,mqcd,xssex,price from student where 1=1"
而且你的每个AND前面都要空出一格
例:sql=sql&"and xssex like '%"&xssex&"%' "
sql=sql&" and xssex like '%"&xssex&"%' "
- 这里要空格
xihasky 2004-12-25
  • 打赏
  • 举报
回复
我试一下
91jk 2004-12-25
  • 打赏
  • 举报
回复
fdkemu,mqcd,xssex,price ,id就这些了
91jk 2004-12-25
  • 打赏
  • 举报
回复
楼上的,那我这一句应该怎么写呢?
加载更多回复(4)

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧