Asp improves execution efficiency

Source: Internet
Author: User

<%
Function DisplayRecords ()
Dim SQL, conn, rs
SQL = "select [id], [st], [nd] from [table]"
Set conn = Server. CreateObject ("ADODB. Connection ")
Conn. Open "DRIVER = {Microsoft Access Driver (*. mdb)}; DBQ =" & Server. MapPath ("Database. mdb ")
Set rs = Server. CreateObject ("ADODB. Recordset ")
Rs. Open SQL, conn, 1, 3

If Not rs. EOF Then
Dim temp
Temp = "<table width =" "90%" "align =" "center """
Temp = temp & "border =" "1" "bordercolor =" "silver """
Temp = temp & "cellspacing =" "2" "cellpadding =" "0">"
Temp = temp & "<tr bgcolor =" "# CCDDEE" "> <td width =" 5% """
Temp = temp & "> ID </td> <td> Operation </td>"
Temp = temp & "<td> value </td> </tr>"

While Not rs. EOF
Temp = temp & "<tr> <td bgcolor =" "# CCDDEE" ">"
Temp = temp & rs ("ID") & "</td> <td>" & rs ("st ")
Temp = temp & "</td> <td>" & rs ("nd ")
Temp = temp & "</td> </tr>"
Rs. MoveNext
Wend
Temp = temp & "</table>"
DisplayRecords = temp
Else
DisplayRecords = "Data Not Available ."
End If

Rs. Close
Conn. Close
Set rs = Nothing
Set conn = Nothing
End Function

'Write cache
Function DisplayCachedRecords (Secs)
Dim retVal, datVal, temp1
RetVal = Application ("cache_demo ")
DatVal = Application ("cache_demo_date ")

If datVal = "" Then
DatVal = DateAdd ("s", Secs, Now)
End If

Temp1 = DateDiff ("s", Now, datVal)

If temp1> 0 And retVal <> "" Then
DisplayCachedRecords = retVal
Response. Write "<B> <font color =" "green"> Use cache to read data"
Response. Write "... (" & temp1 & "seconds remaining) </font> </B>"
Response. Write "<br>"
Else

Dim temp2
Temp2 = DisplayRecords ()

Application. Lock
Application ("cache_demo") = temp2
Application ("cache_demo_date") = DateAdd ("s", Secs, Now)
Application. UnLock

DisplayCachedRecords = temp2

Response. Write "<B> <font color =" red "> refresh cache display ..."
Response. Write "</font> </B> <br>"

End If
End Function
%>
<Html>
<Head>
<Title> use the cache to read data from the database --- </title>
<Style>
Body, p, td {font-family: ""; font-size: 12px ;}
Td {padding: 5px ;}
</Style>
</Head>
<Body>
<%
Dim t1, t2
T1 = Timer
Response. Write DisplayCachedRecords (60)
T2 = Timer
%>

<P align = "center">
Stay Time: <% = Left (CDbl (t2-t1) * 1000.0), 5) %> MS
</P>

</Body>
</Html>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.