资讯   |   开发   |   选机中心   |   产品大全 | IBM | 惠普 | 联想 | 戴尔 | 苹果 | 神舟
更多: | 华硕 | 明基 | 方正 | 紫光 | TCL | 夏新 | 联宝 | 宏碁 | 七喜 | 长城 | 清华同方 | 海尔 | 三星 | 东芝 | 索尼 | 富士通 | LG | 技术 | ddnoon
当前位置:笔记本 > 软件开发 >
Advertisement
文章正文

asp连接数据库问题

类型:转载   责任编辑:asp.net   日期:2007/05/23


热门软件下载:


   

在1个页面中如果要2次(以上)调用数据库   该怎么做?  
   
  比如:  
  我的数据库是data.mdb  
  表:article(id,content,title,time)     ,   notice(id,title,content,time)  
   
  conn.asp  
  <%  
  Set   conn   =   Server.CreateObject("ADODB.Connection")  
  connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data   Source="&Server.MapPath("data.mdb")  
  conn.open   connstr  
  If   Err   Then  
  err.Clear  
  Set   Conn   =   Nothing  
  Response.Write   "数据库连接出错,请检查连接字串。"  
  Response.End  
  End   If  
  %>  
   
  <%     sub   notice()  
  sql="select   top   5   *   from   notice   order   by   id   desc"  
  Set   rs=Server.CreateObject("ADODB.Recordset")  
  rs.open   sql,conn,1,1  
      Do   While   not   rs.eof  
  %>      
      <TR   height="25">  
      <TD   width=99%><%   =rs("title")%>&nbsp&nbsp&nbsp<%   =month(rs("time"))   %>-<%   =day(rs("time"))   %></td>  
      </TR>  
  <%  
  rs.movenext  
  if   rs.eof   then   exit   do  
  loop  
  rs.close  
  set   rs=nothing  
  conn.close  
  set   conn=nothing  
  end   sub  
  %>  
   
  <%    
  sub   article_pop()  
  sql="select   top   5   *   from   article   order   by   id   desc"  
  Set   rs=Server.CreateObject("ADODB.Recordset")  
  rs.open   sql,conn,1,1  
      Do   While   not   rs.eof  
  %>      
      <TR   height="20">  
      <TD   width="80%"><%   =rs("title")%></td>  
      <td   width="20%"><%   =month(rs("time"))   %>-<%   =day(rs("time"))   %></td>  
      </TR>  
  <%  
  rs.movenext  
  if   rs.eof   then   exit   do  
  loop  
  rs.close  
  set   rs=nothing  
  conn.close  
  set   conn=nothing  
  end   sub  
  %>  
   
   
  display.asp页面  
  <html>  
  <body>  
  <table   width=400   border=1>  
  <tbody>  
  <%   call   notice()%   >     第一次  
  </tbody>  
  </table>  
  <table   width=400   border=1>  
  <tbody>  
  <%   call   article_pop()%>     第2次  
  </tbody>  
  </table>  
  </body>  
  </html>  
   
   
  为什么只显示第一次调用的     不显示第二次调用的数据呢    
   
  请高手们给小弟讲讲     谢谢!!~~~~~  
  (我是初学asp:)     分数不多了   不要介意哦:))  
   
   
 

网友回答:

发表者:777dragon

调用没错de    
   
  如这样的可以:  
  <%      
  sub   notice()  
      Response.Write("Call   1")    
  End   sub  
  %>      
  <%      
  sub   article_pop()  
      Response.Write("Call   2")    
  End   sub  
  %>  
  <html>  
  <body>  
  <table   width=400   border=1>  
  <tbody>  
  <%   Call   notice()   %>  
  </tbody>  
  </table>  
  <table   width=400   border=1>  
  <tbody>  
  <%   Call   article_pop()   %>  
  </tbody>  
  </table>  
  </body>  
  </html>  
   
  第二rs改rs1试试   |||   寒~~

发表者:zhuier

我曾经一个用rs,另一个用conn.execute(……)实现的,你可以试试,因为我那个当时不需要两次rs调用,所以没有碰到你的情况。  
  或者设置两个不同的ADODB.Connection试一下

发表者:rabbit666

设置两次rs是没错的  
  用rs   rs1也是对的

发表者:522jack

up  
 

发表者:hoterran

为什么把conn给关了,关了   谁连接数据库??

发表者:a040liutao

在过程里都关闭了CONN   掉用第一个过程结束后conn.close而且set   conn=nothing  
  第2个过程就没有conn对象可用了   当然不行,写一个专门的过程来关闭和释放conn,在程序结束时调用一下这个过程  
 


 

 
热门推荐笔记本: 夏新笔记本
相关文章:
webmaster:popbb@126.com   最佳浏览:1024X768 MSIE
©2007 popbb.net All Rights Reserved