<! -- Frog recommendation: clever use of cache to improve ASP program performance -->
<! -- To Improve the Performance of ASP programs, people often cache frequently used data in applications,
But how can I 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 with me. Thank you.
-->
<%
Class wawa_app_getrows
Public Function wawa_get_list (Strapp, strconn, strsql)
'********************************
'Function: extract arrays from the application. If the data in the application is empty, call the wawa_get_rows () function to assign values to the application.
', You can clear the corresponding application value to empty when modifying the database, which will automatically update the application during browsing.
'If you have updated the database (such as adding, modifying, or deleting data), remove the corresponding application variable after modifying the database,
'Use the following statement to clear the specified application value. The Strapp parameter is the name of the application variable to be removed.
'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 records 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
%>
<! -- The following example shows how to use the class above -->
<%
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 = '000000' 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> ")
%>