In order to improve the performance of ASP program, people often use the data cached in application, but you modify the database how to let application update, this article gives you a reasonable solution.
<%
Class wawa_app_getrows
Public Function wawa_get_list (strapp,strconn,strsql)
'********************************
' Function: Extract the array from the application, and then call the Wawa_get_rows () function to assign a value to the application if the data in application is a empty value.
' You can empty the corresponding application value into empty when you modify the database, which automatically updates the application when you browse.
' If you update the database (for example, add, modify, or delete the data) then remove the corresponding application variable after modifying the database,
' Use one of the following statements to empty the specified application value, where the Strapp parameter is the application variable name to remove
' Application. Contents.Remove (Strapp)
'********************************
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 the record from the database and use the GetRows method
' Save the record as 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
%>
!--below for an example to illustrate how the above class uses-->
<%
Dim strapp,strsql,strconn
strapp= "Employee"
Strsql= "Select employeeid,titleofcourtesy,firstname,lastname,title,city from Employees"
strconn= "Driver={sql Server};server=192.168.0.110;database=northwind;uid=sa;pwd=sa;"
Set Wawa_temp=new wawa_app_getrows
Arr_wawa=wawa_temp.wawa_get_list (Strapp,strconn,strsql)
%>
<%
Response.Write ("<table width= ' 100% ' border= ' 0 ' cellspacing= ' 1 '")
Dim I,j,rows,flds
Rows=ubound (arr_wawa,2)
Flds=ubound (arr_wawa,1)
If rows>=0 Then
For I=0 to Rows
Response.Write ("<tr>")
For J=0 to Flds
Response.Write "<td>" &arr_wawa (j,i) & "</td>"
Next
Response.Write ("</tr>")
Next
Else
Response.Write ("<tr> <td>" &Rows& "</td> </tr>")
End If
Response.Write ("</table>")
%>