永发信息网

ASP错误:对象关闭时,不允许操作!!

答案:6  悬赏:50  手机版
解决时间 2021-01-29 07:23
  • 提问者网友:谁的错
  • 2021-01-28 06:50
&lt;%<br>sub NewsEdit()<br>  dim Action,rsCheckAdd,rs,sql<br>  Action=request.QueryString(&quot;Action&quot;)<br>  if Action=&quot;SaveEdit&quot; then<br>  set rs = server.createobject(&quot;adodb.recordset&quot;)<br>  if len(trim(request.Form(&quot;NewsName&quot;)))&lt;1 then<br>  response.write (&quot;&lt;script language=javascript&gt; alert('新闻标题为必填项目!');history.back(-1);&lt;/script&gt;&quot;)<br>  response.end<br>  end if<br>  if Result=&quot;Add&quot; then<br>  sql=&quot;select * from NwebCn_News&quot;<br>  rs.open sql,conn,1,3<br>  rs.addnew<br>  rs(&quot;NewsName&quot;)=trim(Request.Form(&quot;NewsName&quot;))<br>  rs(&quot;Content&quot;)=Request.Form(&quot;Content&quot;)<br>  GroupIdName=split(Request.Form(&quot;GroupID&quot;),&quot;┎╂┚&quot;)<br>  rs(&quot;GroupID&quot;)=GroupIdName(0)<br>  rs(&quot;Exclusive&quot;)=trim(Request.Form(&quot;Exclusive&quot;))<br>  if Request.Form(&quot;ChildFlag&quot;)=1 then<br>  rs(&quot;ChildFlag&quot;)=Request.Form(&quot;ChildFlag&quot;)<br>  rs(&quot;Sequence&quot;)=999<br>  else<br>  rs(&quot;ChildFlag&quot;)=0<br>  rs(&quot;Sequence&quot;)=99<br>  end if<br>  rs(&quot;AddTime&quot;)=now()<br>  rs(&quot;UpdateTime&quot;)=now()<br>  end if  <br>  if Result=&quot;Modify&quot; then<br>  sql=&quot;select * from NwebCn_News where ID=&quot;&amp;ID<br>  rs.open sql,conn,1,3<br>  rs(&quot;NewsName&quot;)=trim(Request.Form(&quot;NewsName&quot;))<br>  rs(&quot;Content&quot;)=Request.Form(&quot;Content&quot;)<br>  GroupIdName=split(Request.Form(&quot;GroupID&quot;),&quot;┎╂┚&quot;)<br>  rs(&quot;GroupID&quot;)=GroupIdName(0)<br>  rs(&quot;Exclusive&quot;)=trim(Request.Form(&quot;Exclusive&quot;))<br>  if Request.Form(&quot;ChildFlag&quot;)=1 then<br>  rs(&quot;ChildFlag&quot;)=Request.Form(&quot;ChildFlag&quot;)<br>  rs(&quot;Sequence&quot;)=100<br>  else<br>  rs(&quot;ChildFlag&quot;)=0<br>  end if<br>  rs(&quot;UpdateTime&quot;)=now()<br>  end if<br>  rs.update   ----------运行的时候这行报错:对象关闭时,不允许操作<br>  rs.close<br>  set rs=nothing <br>    response.write &quot;&lt;script language=javascript&gt; alert('成功编辑新闻信息!');changeAdminFlag('新闻信息列表');location.replace(NewsList.asp');&lt;/script&gt;&quot;<br>  else<br>  if Result=&quot;Modify&quot; then<br>      set rs = server.createobject(&quot;adodb.recordset&quot;)<br>      sql=&quot;select * from NwebCn_News where ID=&quot;&amp; ID<br>      rs.open sql,conn,1,1<br>NewsName=rs(&quot;NewsName&quot;)<br>GroupID=rs(&quot;GroupID&quot;)<br>Exclusive=rs(&quot;Exclusive&quot;)<br>Content=rs(&quot;Content&quot;)<br>ChildFlag=rs(&quot;ChildFlag&quot;)<br>rs.close<br>set rs=nothing <br> end if<br>end if<br>end sub<br>%&gt;<br>--------------------------<br>高手帮忙看下,是什么原因,感谢。。<br>&lt;% <br>dim Result<br>Result=request.QueryString(&quot;Result&quot;)<br>dim ID,NewsName,Content<br>dim GroupID,GroupIdName,Exclusive,ChildFlag,Source<br>ID=request.QueryString(&quot;ID&quot;)<br>call NewsEdit() <br>%&gt;<br>有Result=Request.QueryString(&quot;Result&quot;)这句的。虽然添加不了,但可以修改,就是说Modify的值是可以取到的,那为什么不能添加呢?下面这句应该正确吧?&lt;form action=&quot;NewsEdit.asp?Action=SaveEdit&amp;Result=&lt;%=Result%&gt;&amp;ID=&lt;%=ID%&gt;&quot;&gt;
最佳答案
  • 五星知识达人网友:想偏头吻你
  • 2021-01-28 07:55
不要偷懒嘛~!!! <br>把rs.update那三行分别放到那两个块后面 <br>&lt;% <br>sub NewsEdit() <br>dim Action,rsCheckAdd,rs,sql <br>Action=request.QueryString(&quot;Action&quot;) <br>if Action=&quot;SaveEdit&quot; then <br>set rs = server.createobject(&quot;adodb.recordset&quot;) <br>if len(trim(request.Form(&quot;NewsName&quot;)))&lt;1 then <br>response.write (&quot;&lt;script language=javascript&gt; alert('新闻标题为必填项目!');history.back(-1);&lt;/script&gt;&quot;) <br>response.end <br>end if <br>if Result=&quot;Add&quot; then <br>sql=&quot;select * from NwebCn_News&quot; <br>rs.open sql,conn,1,3 <br>rs.addnew <br>rs(&quot;NewsName&quot;)=trim(Request.Form(&quot;NewsName&quot;)) <br>rs(&quot;Content&quot;)=Request.Form(&quot;Content&quot;) <br>GroupIdName=split(Request.Form(&quot;GroupID&quot;),&quot;┎╂┚&quot;) <br>rs(&quot;GroupID&quot;)=GroupIdName(0) <br>rs(&quot;Exclusive&quot;)=trim(Request.Form(&quot;Exclusive&quot;)) <br>if Request.Form(&quot;ChildFlag&quot;)=1 then <br>rs(&quot;ChildFlag&quot;)=Request.Form(&quot;ChildFlag&quot;) <br>rs(&quot;Sequence&quot;)=999 <br>else <br>rs(&quot;ChildFlag&quot;)=0 <br>rs(&quot;Sequence&quot;)=99 <br>end if <br>rs(&quot;AddTime&quot;)=now() <br>rs(&quot;UpdateTime&quot;)=now() <br>rs.update <br>rs.close <br>set rs=nothing <br><br>end if <br>if Result=&quot;Modify&quot; then <br>sql=&quot;select * from NwebCn_News where ID=&quot;&amp;ID <br>rs.open sql,conn,1,3 <br>rs(&quot;NewsName&quot;)=trim(Request.Form(&quot;NewsName&quot;)) <br>rs(&quot;Content&quot;)=Request.Form(&quot;Content&quot;) <br>GroupIdName=split(Request.Form(&quot;GroupID&quot;),&quot;┎╂┚&quot;) <br>rs(&quot;GroupID&quot;)=GroupIdName(0) <br>rs(&quot;Exclusive&quot;)=trim(Request.Form(&quot;Exclusive&quot;)) <br>if Request.Form(&quot;ChildFlag&quot;)=1 then <br>rs(&quot;ChildFlag&quot;)=Request.Form(&quot;ChildFlag&quot;) <br>rs(&quot;Sequence&quot;)=100 <br>else <br>rs(&quot;ChildFlag&quot;)=0 <br>end if <br>rs(&quot;UpdateTime&quot;)=now() <br>rs.update <br>rs.close <br>set rs=nothing <br>end if <br><br>response.write &quot;&lt;script language=javascript&gt; alert('成功编辑新闻信息!');changeAdminFlag('新闻信息列表');location.replace(NewsList.asp');&lt;/script&gt;&quot; <br>else <br>if Result=&quot;Modify&quot; then <br>set rs = server.createobject(&quot;adodb.recordset&quot;) <br>sql=&quot;select * from NwebCn_News where ID=&quot;&amp; ID <br>rs.open sql,conn,1,1 <br>NewsName=rs(&quot;NewsName&quot;) <br>GroupID=rs(&quot;GroupID&quot;) <br>Exclusive=rs(&quot;Exclusive&quot;) <br>Content=rs(&quot;Content&quot;) <br>ChildFlag=rs(&quot;ChildFlag&quot;) <br>rs.close <br>set rs=nothing <br>end if <br>end if <br>end sub <br>%&gt;<br><br>补充:看了你代码,你只取了Action,没取Result啊。。。。<br>if Result=&quot;Add&quot; then <br>在这句之前没有Result的取值语句。在前面加上一句<br>Result=Request.QueryString(&quot;Result&quot;)
全部回答
  • 1楼网友:行雁书
  • 2021-01-28 12:19
测测试网页的时候要关闭数据库的编辑页面
  • 2楼网友:长青诗
  • 2021-01-28 11:35
可以加个 on Error resume next
  • 3楼网友:动情书生
  • 2021-01-28 10:36
楼上说的对,不要偷懒! 错误原因在于你传来的result 值 既不是add 也不是Modify 所以数据库根本没有打开,你就update 肯定出错的 你根本没有给Result赋值 ????
  • 4楼网友:爱难随人意
  • 2021-01-28 10:17
当 Result 不是那两个值时 Rs就没被打开 是不是? 最好把 rs.update rs.close 分别放到 IF 块里面去
  • 5楼网友:从此江山别
  • 2021-01-28 08:39
你好! if 真复杂,你整理一下估计就知道怎么错了,估计是这种情况了 if **** set rs= 。。。。。 end if rs.update rs.close rs相关语句写到一块就行了 打字不易,采纳哦!
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯