<!--为了提高asp程序的性能,人们常常将经常使用的数据缓存在 application,
但是你修改了数据库后怎么让application更新呢,本文给你提供了一个合理的解决办法,
如果谁有更好的算法,请跟帖讨论一下,谢谢
-->
<%
class wawa_app_getrows
public function wawa_get_list(strapp,strconn,strsql)
'********************************
'功能:从application中提取数组,如果application中的数据为empty值的时候再调用wawa_get_rows()函数来给application赋值.
' ,你可以在修改数据库的时候把相应的application值清空成empty,这就浏览的时候就会自动更新application了
' 如果你更新了数据库(比如说添加,修改或者删除了数据)那么在修改数据库后把相应的application变量去掉,
' 用下面的一条语句来实现清空指定的application值,其中strapp参数是要去掉的application变量名
' application.contents.remove(strapp)
' www.knowsky.com
'********************************
dim wawa
wawa = application(strapp)
if isempty(wawa) then
wawa = wawa_get_rows(strconn,strsql)
application(strapp) = wawa
end if
wawa_get_list = wawa
end function
public function wawa_get_rows(strconn,strsql)
'********************************
'功能:从数据库里读取记录并用getrows方法
' 把记录保存成一个数组
'
'********************************
dim rs_wawa
set rs_wawa = createobject("adodb.recordset")
rs_wawa.open strsql,strconn,,1,1
wawa_get_rows = rs_wawa.getrows()
rs_wawa.close
set rs_wawa = nothing
end function
end class
%>
<!-- 下面举个例子来说明上面的那个类怎么使用 -->
<%
dim strapp,strsql,strconn
strapp="xinwendongtai"
strsql="select top 5 id,title from wen where lei=161 order by id desc"
strconn="driver={sql server};server=192.168.0.110;database=new;uid=sa;pwd=sa;"
set wawa_temp=new wawa_app_getrows
arr_xinwendongtai=wawa_temp.wawa_get_list(strapp,strconn,strsql)
%>
<table width="100%" border="0" cellspacing="1">
<% if ubound(arr_xinwendongtai)<>0 then %>
<% for i=0 to ubound(arr_xinwendongtai,2)-1 %>
<tr>
<td><a href="view.asp?id=<%= arr_xinwendongtai(0,i) %>"><%= arr_xinwendongtai(1,i) %></a></td>
</tr>
<% next %>
<% else %>
<tr>
<td>还没有新闻呢</td>
</tr>
<% end if %>
</table>
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器