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

【求助】RS,CONN关闭

theend12 发布于 2010-06-16 16:16, 550 次点击
<!--#include file = "conn.asp"-->
<%
if session("admin")= "" Then   ' 判断登录状态
response.write "<script>alert('非法登陆 ');location.href='admin_login.asp'</script>"
end If
%>
<%
If request("send")=" 修改链接" Then
Dim h_id,h_name,h_url,h_info,h_qq,rs5,mysql5
id=request("id")
h_name=request("name")
h_url=request("url")
h_info=request("info")
h_qq=request("qq")
%>

<%
'=========================================================================
' 数据库操作:将用户信息录入到数据库
set rs5 = server.createobject("adodb.recordset")
mysql5 = "update [h_friend] set name = '"&h_name&"',url = '"&h_url&"',info = '"&h_info&"',qq = '"&h_qq&"'where ID = "&id
rs5.Open mysql5,conn,1,3
response.write "<script>alert("" 链接修改成!"");location.href=""admin_friend.asp"";</script>"
rs5.close
Set rs5 = Nothing
conn.close
Set conn=nothing
End If
%>

------------------------------------------ 以上是代码---------------------------------------------
执行后提示:
ADODB.Recordset (0x800A0E78)
对象关闭时,不允许操作。

关闭RS,CONN,挪了半天也不知道方在哪里,怎么都放在最后了还是不行呢?应该怎么放? 关闭RS和CONN要放哪?

3 回复
#2
icecool2010-06-16 17:00
因为你的更新语句中根没有用到rs5记录集,
没有打开,所以不存在关闭. 即可以去掉set rs5 = server.createobject("adodb.recordset")
再去掉
rs5.close
Set rs5 = Nothing
#3
yms1232010-06-16 17:00
set rs5 = server.createobject("adodb.recordset")
mysql5 = "update [h_friend] set name = '"&h_name&"',url = '"&h_url&"',info = '"&h_info&"',qq = '"&h_qq&"'where ID = "&id
rs5.Open mysql5,conn,1,3
response.write "<script>alert("" 链接修改成!"");location.href=""admin_friend.asp"";</script>"
rs5.close
Set rs5 = Nothing
conn.close
Set conn=nothing
End If
Update要么用rs来Update要么直接用conn.execute,这种用法肯定错误,不知楼主看哪本书这样写的?
用法1
mysql5 = "update [h_friend] set name = '"&h_name&"',url = '"&h_url&"',info = '"&h_info&"',qq = '"&h_qq&"'where ID = "&id
conn.execute mysql5
response.write "<script>alert("" 链接修改成!"");location.href=""admin_friend.asp"";</script>"
conn.close
Set conn=nothing
End If
用法2
set rs5 = server.createobject("adodb.recordset")
mysql5 = "select * from [h_friend] where ID="&id
rs5.Open mysql5,conn,1,3
rs5("name")=h_name
rs5("url")=h_url
rs5("info")=h_info
rs5("qq")=h_qq
rs5.update
response.write "<script>alert("" 链接修改成!"");location.href=""admin_friend.asp"";</script>"
rs5.close
Set rs5 = Nothing
conn.close
Set conn=nothing
End If
#4
theend122010-06-16 17:18
谢谢上面2位哥哥的回答了,我是自学的,刚刚学。解释的很详细。明白了
1