onlytiancai [original work]
<!--In order to improve the performance of Asp programs, people often cache frequently used data in Application,
But how do you update the application after you modify the database? This article provides you with a reasonable solution.
If anyone has a better algorithm, please discuss it in the thread, thank you
-->
<%
Class wawa_app_getrows
public Function wawa_Get_List(strapp,strconn,strsql)
'************************************
'Function: Extract the array from the Application. If the data in the application is empty, then call the wawa_Get_Rows() function to assign a value to the application.
' , you can clear the corresponding application value to empty when modifying the database, so that the application will be automatically updated when browsing.
' If you update the database (for example, add, modify or delete data) then remove the corresponding application variables after modifying the database,
'Use the following statement to clear the specified application value, where the strapp parameter is the name of the application variable to be removed
' application.Contents.Remove(strapp)
' www.downcodes.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)
'**********************************
'Function: read records from the database and use the getrows method
'Save the record into an array
'
'************************************
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
%>
<!-- Here is an example to illustrate how to use the above 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>No news yet</td>
</tr>
<% End If %>
</table>