一个简单ASP数据库问题 200分 在线等(200)

  • 主题发起人 主题发起人 happycat1988
  • 开始时间 开始时间
H

happycat1988

Unregistered / Unconfirmed
GUEST, unregistred user!
<%Dim connset conn=Server.CreateObject("ADODB.Connection")conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("mydb.mdb")Dim rs1,rs2set rs1 = Server.CreateObject("ADODB.RecordSet")rs1.open "select * from area order by orderid",connset rs2 = Server.CreateObject("ADODB.RecordSet")%><table width="70%" border="1" align="center"><%Do While Not rs1.Eof%> <tr> <td width="30%"><%=rs1("areaname")%></td> <td><%=rs1("memo")%></td> </tr> <% rs2.open "select * from board where areaid=" & rs1("id") & " order by orderid",conn Do While Not rs2.Eof %> <tr> <td width="30%"><%=rs2("boardname")%></td> <td><%=rs2("memo")%></td> </tr> <% rs2.MoveNext Loop %><%rs1.MoveNextLoop%></table></html><%rs2.closers1.closeconn.Closeset rs2 = nothingset rs1 = nothingset conn = nothing%>执行的时候出错错误类型:ADODB.Recordset (0x800A0E79)对象打开时,不允许操作。在这行rs2.open "select * from board where areaid=" & rs1("id") & " order by orderid",conn我是用2个recordset分别显示2个表中的内容 他们之间有关联 所以用了嵌套循环 请问那里有错? 难道不能同时对数据库用2个recordset显示数据吗? 我是asp新手 会的请帮下
 
rs2.open "select * from board where areaid=" & rs1("id") & " order by orderid",conn前面加一句rs2.close
 
加上rs2.close 之后变成错误类型:ADODB.Recordset (0x800A0E78)对象关闭时,不允许操作。
 
Do While Not rs1.Eof 改用 For 试一试
 
rs2.close 加在Open前面或是加在Rs1.Movenext前面,应该没有问题的,你检查一下位置
 
任何语言里面的数据集都要先关闭再打开。
 
有谁能把关键部分改下不?
 
纯顶,纯接分飘过
 
另外一句 sql 不就解决了吗?select board.*,area.* from board left join area on board.areaid=area.id where areaid in (select id from area)
 
<% set rs2 = Server.CreateObject("ADODB.RecordSet") '放到循环里来 rs2.open "select * from board where areaid=" & rs1("id") & " order by orderid",conndo
While Not rs2.Eof %> <tr> <td width="30%"><%=rs2("boardname")%></td> <td><%=rs2("memo")%></td> </tr> <% rs2.MoveNext Loop rs2.close '加close %>
 
根据scxujie所说 修改后文件为<html><body><%Dim connset conn=Server.CreateObject("ADODB.Connection")conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("mydb.mdb")Dim rs1,rs2set rs1 = Server.CreateObject("ADODB.RecordSet")rs1.open "select * from area order by orderid",conn%><table width="70%" border="1" align="center"><%Do While Not rs1.Eof%> <tr> <td width="30%"><%=rs1("areaname")%></td> <td><%=rs1("memo")%></td> </tr> <% set rs2 = Server.CreateObject("ADODB.RecordSet") rs2.open "select * from board where areaid=" & rs1("id") & " order by orderid",conndo
While Not rs2.Eof %> <tr> <td width="30%"><%=rs2("boardname")%></td> <td><%=rs2("memo")%></td> </tr> <% rs2.MoveNext Loop rs2.close %><%rs1.MoveNextLoop%></table></body></html><%rs1.closeconn.Closeset rs2 = nothingset rs1 = nothingset conn = nothing%>调试成功
 
scxujie所说的select board.*,area.* from board left join area on board.areaid=area.id where areaid in (select id from area)能说明下具体asp代码如何编写不? 我只要areaname显示一次 然后紧跟着这个area下的所有boardname都要显示出来
 
多人接受答案了。
 
后退
顶部