asp 读取数据

xsun02 2004-09-30 02:20:17
我做的新闻发布系统,为什么不能动态读取新闻内容
新闻内容显示代码是这样的(读取数据库部分)
<%
dim theid
theid=request("new_id")
set rs=server.createobject("ADODB.Recordset")
sql="select* from new where new_id='&theid'"
rs.open sql,conn,1,1
%>
提示出错信息是:无法打开数据库,请问各路高手是怎么回事哦?
...全文
129 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
码到末日 2004-09-30
  • 打赏
  • 举报
回复
明显错误:
sql="select* from new where new_id='&theid'"

是因为在“select”和“*”之间没有空格吧?

以后注意点!
cqpower 2004-09-30
  • 打赏
  • 举报
回复
明显错误:
sql="select* from new where new_id='&theid'"
改为:
new_id 数据类型为非数字类型时
sql="select * from new where new_id='" & theid & "'"
new_id 数据类型为数字类型时
sql="select * from new where new_id=" & theid
iuhxq 2004-09-30
  • 打赏
  • 举报
回复
各位真是高手啊,不会数据库操作的都可以在一个帖子内教会
wanghongtaoleifeng 2004-09-30
  • 打赏
  • 举报
回复
sql="select* from new where new_id='"


sql=sql& "theid & "'"

ok?
catchme 2004-09-30
  • 打赏
  • 举报
回复
sql="select* from new where new_id='"&theid&"'"
satans18 2004-09-30
  • 打赏
  • 举报
回复
数字用 id='&id
xsun02 2004-09-30
  • 打赏
  • 举报
回复
谢谢个位
wwj9252003 2004-09-30
  • 打赏
  • 举报
回复
自动增长型的话,
sql="select * from new where new_id=" & theid  这样肯定没有错
你可以把theid 这个值response.write 或者sql 也response.write
这样问题就很明显了
另外去掉ie的显示友好错误信息,看一下真实的错误信息是什么?
mikespook 2004-09-30
  • 打赏
  • 举报
回复
我忽略了一个问题

sql="select* from [new] where new_id=" & theid

加上方括号看看~~
tpf9000 2004-09-30
  • 打赏
  • 举报
回复
3573745(※∷超≌√) ( ) 信誉:100
说的很全,很明白
tpf9000 2004-09-30
  • 打赏
  • 举报
回复
楼上说的很明白哦,都说全了,你在试试,应该可以了
VickyMao 2004-09-30
  • 打赏
  • 举报
回复
sql="select* from new where new_id='&theid'"

改为

sql="select* from new where new_id='" & theid & "'"
3573745 2004-09-30
  • 打赏
  • 举报
回复
首先确保你的数据库已经打开
然后打开数据库
sql="select * from new where new_id="&request("news_id")
或者
newsid=request("news_id")
sql="select* from new where new_id=""&newsid&"" '/假如你的NEWS_ID是自动编号!
sql="select* from new where new_id="'"&newsid&"'" '/假如你的NEWS_ID是数字行或者CHAT的
OK 就这么多了!应该明白了吧!
Qlike 2004-09-30
  • 打赏
  • 举报
回复
你的SQL 语句写错了,
应该这样:sql="select* from new where new_id='"&theid&"'"
xsun02 2004-09-30
  • 打赏
  • 举报
回复
楼上mikespook(懒猫开始新生活) 大兄,那样也不行,我试了,
ID传递在连接的时候可以看出它已经传了,(从IE状态栏看到的)
fashchina 2004-09-30
  • 打赏
  • 举报
回复
我晕
我的方法不行/
先看看theid传过来没
然后用我的方法
mikespook 2004-09-30
  • 打赏
  • 举报
回复
sql="select* from new where new_id='&theid'"

改为

sql="select* from new where new_id=" & theid
xsun02 2004-09-30
  • 打赏
  • 举报
回复
我在access建的数据库,new_id 是自动增长型的
xsun02 2004-09-30
  • 打赏
  • 举报
回复
是的,我在写字版写的,正常打开数据没问题,
就是加了
sql="select* from new where new_id='&theid'"
这句就不行了
mickguo 2004-09-30
  • 打赏
  • 举报
回复
你的代码是在“记事本”里写的吗?怎么如此不规范!
<%
dim theid
theid=request("new_id")

set rs=server.createobject("ADODB.Recordset")
sql="select* from new where new_id='"&theid&"'"
rs.open sql,conn,1,1 'conn数据链接打开正确吗?
%>
加载更多回复(1)

28,408

社区成员

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

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