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 values to application if the data in application is empty value.
', you can change the database when the corresponding application value to empty into the empty, this will be automatically updated when browsing application
' If you update the database (for example, add, modify, or delete data) then remove the corresponding application variable after modifying the database,
' uses the following statement to empty the specified application value, where the Strapp parameter is the application variable name 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: Reading records from a database and using GetRows method
' Saves 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>")
%>
|