|
蓝森林 http://www.lslnet.com 2006年8月25日 8:28
[ASP] 数据库连接更新问题
Dim z_update_tid,z_update_done
z_update_tid = Request.QueryString("tid")
Dim rs,count,sql
set rs=server.createobject("adodb.recordset")
count="select count(*) as Topic_Done_Times from [do] where z_tid="&z_update_tid
rs.open count,conn,1,1
z_update_done = rs("Topic_Done_Times")
z_update_done = z_update_done + 0
[color=Red]rs.close[/color]
sql="update [topic] set z_done="&z_update_done&" where z_tid="&z_update_tid
rs.open sql,conn,1,3
rs.close
Set rs = Nothing
conn.close
set conn=nothing
我把[color=Red]rs.close[/color]放在那他显示: 对象关闭时,不允许操作。
我再把他去掉,变成了: 对象打开时,不允许操作。
请高手帮忙解答,谢谢! |
这个页面中有别的包含文件没有?!~
也许是你的包含文件关闭了数据库! |
呵呵,很遗憾,没有你说的情况。 |
这么看没啥问题。
报错的行号是这里吗? |
<!--#include file="conn.asp"-->
<!--#include file="error.asp"-->
<%
Dim z_update_tid,z_update_done
z_update_tid = Trim(Request.QueryString("tid"))
If z_update_tid="" or IsNull(z_update_tid) Then
Response.Write "查询条件不能为空。"
Response.End
End If
If Not IsNumeric(z_update_tid) Then
Response.Write "查询条件必须是数字。"
Response.End
End If
z_update_tid=Clng(z_update_tid)
If z_update_tid<=0 Then
Response.Write "查询条件不能为零或为负数。"
Response.End
End If
Dim rs,count,renew
set rs=server.createobject("adodb.recordset")
count="select count(*) as Topic_Done_Times from [do] where z_tid="&z_update_tid
rs.open count,conn,1,1
z_update_done = rs("Topic_Done_Times") + 0
If z_update_done = 0 Then
z_error_title = "更新结果"
z_error_msg = "你所要更新的题目不存在或尚未有人回答。"
call z_error(z_error_title,z_error_msg,0)
End If
rs.close
renew="update [topic] set z_done="&z_update_done&" where z_tid="&z_update_tid
rs.open renew,conn,1,3
REM @1
[color=Red]If Err Then
Response.Write "错误代号:" & Server.HTMLEncode(Err.Number) & "<br>" '错误信息语句仅供调试程序时使用
Response.Write "错误描述:" & Server.HTMLEncode(Err.Description) & "<br>"
Err.Clear
'z_error_title = "更新结果"
'z_error_msg = "很抱歉,由于系统错误,更新失败!"
'call z_error(z_error_title,z_error_msg,0)
Else
z_error_title = "更新结果"
z_error_image = "<img src=""images/joy.jpg"" width=""100"" height=""100"" border=""0"">"
z_error_msg = "编号为"& z_update_tid &"的题目被回答"& z_update_done &"次,更新成功!"
call z_error(z_error_title,z_error_msg,z_error_image)
End If[/color]
rs.close
Set rs = Nothing
conn.close
Set conn = Nothing
REM@2
%>
我现在是把红色部分放在@1位置,这样没错误,可以更新成功,但是如果我把红色部分放到@2位置时,就会出错,您试试看!
不知道是什么原因?
|
相关页面
http://www.kenken.cn/friend/topic_done_update.asp?tid=23
http://www.kenken.cn/friend/do.asp?key=C4sj9lU8LAa
:) |
萧萧小雨
有解释吗? |
- - !~~~~~~~~~~~up~~~~~~~~~~ |
曾经也遇到过,一样感到迷惑。
有时你在rs.close前加一行response.write " "就可以 |
我觉得应该这样写:
Dim rs,count,sql
set rs=server.createobject("adodb.recordset")
count="select count(*) as Topic_Done_Times from [do] where z_tid="&z_update_tid
rs.open count,conn,1,1
z_update_done = rs("Topic_Done_Times")
z_update_done = z_update_done + 0
rs.close
Set rs = Nothing
set rs=server.createobject("adodb.recordset")
sql="update [topic] set z_done="&z_update_done&" where z_tid="&z_update_tid
rs.open sql,conn,1,3
rs.close
conn.close
set conn=nothing
因为一个对象在没有关闭时,不允许执行其他的操作;所以说你在执行新的操作之前
要先把上面的对象关闭;因为你在上面已经把要查询的东西赋予“z_update_done ”这个变量了,所以下面的语句中你仍然可以调用它而不受创造它的对象已经关闭的影响,所以说你可以不必担心的关闭它,访问变量和访问对象是两回事。不信的话你可以试一下,下面这个例子,它将会是成功的:
set rs=server.createobject("adodb.recordset")
count="select count(*) as Topic_Done_Times from [do] where z_tid="&z_update_tid
rs.open count,conn,1,1
z_update_done = rs("Topic_Done_Times")
z_update_done = z_update_done + 0
rs.close
Set rs = Nothing ’这两句先关闭和释放对象,下面的那句再输出对象查询的结果,结果是正确的输出了那个结果。
Response.Write z_update_done
|
知道了,光rs.close还不行,还有Set rs = Nothing~~~~~~~
但是Set rs = Nothing的话,下面还要重新set rs=server.createobject("adodb.recordset")
汗的,没其他方法吗?
看来只有把rs清空再…… |
|