ASP + Access 查询后结果为空

minghuan 2006-12-29 10:46:43
<%
dim conn
dim connstr
on error resume next
connstr="DBQ="+server.mappath("mynews.asp")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
conn.open connstr

newstype=request("typeid")
sql="select * from article where shenghe=1 and typeid="+cstr(newstype)+" order by dateandtime desc"
set rs=conn.execute(sql)%>

以上代码,当request("typeid")的值为5时就查询不到,为其他值时就能正常查出来,数据表的数据保证没有问题,请高手赐教!
...全文
223 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
minghuan 2007-01-07
  • 打赏
  • 举报
回复
在本机上运行很正常,但是上传到网站上就不行了,所以觉得很蹊跷!
plought 2006-12-30
  • 打赏
  • 举报
回复
如果依然Request("typeid")的值为5时,查询不到数据。估计是数据表字段typeid的值为5时,另一个字段shenghe的值不为1。
plought 2006-12-30
  • 打赏
  • 举报
回复

''/////楼上已经正解

<%
Dim Conn,newstype,SQLcmd,Rs,
Dim Connstr,DBPATH
newstype=Request("typeid")
DBPATH = Server.mappath("mynews.asp")
on error resume next
Connstr="DBQ="&DBPATH&";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
SET Conn=Server.Createobject("ADODB.CONNECTION")
Conn.open Connstr
if IsNumeric(newstype) then
SQLcmd="select * from article where shenghe=1 and typeid="&newstype
SQLcmd=SQLcmd&" order by dateandtime desc"
else
SQLcmd="select * from article where shenghe=1 and typeid='"&newstype&"'"
SQLcmd=SQLcmd&" order by dateandtime desc"
end if
Set Rs=Conn.execute(SQLcmd)
%>

'/////不需要用cStr处理newstype。
lovebaby 2006-12-29
  • 打赏
  • 举报
回复
从你的Sql语句来看你的typeid字段应该是数字型的,但你为什么又用cstr转换一下呢,另外不清楚你用的什么脚本语言,如果是vbscript的话,把+改成&
sql="select * from article where shenghe=1 and typeid="&newstype&" order by dateandtime desc"

还不行就在sql语句后边加两句
Response.Write(sql)
Response.End
输出一下sql,检查有没有错误,然后放到数据库中执行,查看是否有错误。

28,390

社区成员

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

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