一个ASP递归过程
<%
sub showchild(id,note)
Dim thisid,thisnode
rs2.Source= "select * from treeview where parentid= "&id
rs2.open
if rs2.RecordCount> 0 then
while (not rs2.eof)
thisid=rs2( "id ")
thisnode=rs2( "nodetext ")
Response.write " <li> "
Response.write " <a href= '# '> "¬e& " </a> "
Response.write " <ul> "
call showchild( thisid,thisnode)
Response.write " </ul> "
Response.write " </li> "
rs2.MoveNext
Wend
else
'Response.write " <ul> "
Response.write " <li> <a href= '# '> "¬e& " </a> </li> "
'Response.write " </ul> "
rs2.close
end if
end sub
%>
错误类型:
ADODB.Recordset (0x800A0E78)
对象关闭时,不允许操作。
/glp/mainas.asp, 第 53 行
53:rs2.Source= "select * from treeview where parentid= "&id
问题在于:RS2打开之后,没有打闭导致的.
但是我这个是一个递归过程.该怎么做呀~
------解决方案--------------------try
-------------------------
rs2.Source= "select * from treeview where parentid= "&id
rs2.open
改为
set rs=conn.execute( "select * from treeview where parentid= "&id)
------解决方案--------------------将rs2定义为函数内部的局部变量即可。
<%
sub showchild(id,note)
Dim thisid,thisnode
set rs2.Source= "select * from treeview where parentid= "&id
rs2.open
if rs2.RecordCount> 0 then
while (not rs2.eof)
thisid=rs2( "id ")
thisnode=rs2( "nodetext ")
Response.write " <li> "
Response.write " <a href= '# '> "¬e& " </a> "
Response.write " <ul> "
call showchild( thisid,thisnode)
Response.write " </ul> "
Response.write " </li> "
rs2.MoveNext
Wend
else
'Response.write " <ul> "
Response.write " <li> <a href= '# '> "¬e& " </a> </li> "
'Response.write " </ul> "
rs2.close
end if
end sub
%>
------解决方案--------------------Dim thisid,thisnode, rs2
注意要设置局部变量..
否则会冲突的说.
------解决方案--------------------先建立连接对象,创建对象实例如conn,
创建记录集对象实例如rs
然后用记录集的open方法打开
如果需要读操作可以为
rs.open Source,conn,1,1
写操作为
rs.open Source,conn,1,3