Common functions of ASP.
<%
Dim db
Db = "dbms. mdb"
'*************************************** ***************************
'Execute the SQL statement without returning the value. The SQL statement should be as follows:
'Update table name set field name = value, field name = value where field name = value
'Delete from table name where field name = value
'Insert into Table Name (field name, field name) values (value, value)
'*************************************** ***************************
Sub NoResult (SQL)
Dim conn
Dim connstr
Set conn = Server. CreateObject ("ADODB. Connection ")
Connstr = "Provider = Microsoft. Jet. OLEDB.4.0; Data Source =" & Server. MapPath ("" & db &"")
Conn. Open connstr
Conn.exe cute SQL
Conn. close
Set conn = nothing
End Sub
'*************************************** ****************************
'Execute the select statement and return the recordset object. This object is read-only. That is, it cannot be updated.
'*************************************** ****************************
Function Result (SQL)
Dim conn
Dim connstr
Dim rcs
Set conn = Server. CreateObject ("ADODB. Connection ")
Connstr = "Provider = Microsoft. Jet. OLEDB.4.0; Data Source =" & Server. MapPath ("" & db &"")
Conn. Open connstr
Set rcs = Server. CreateObject ("ADODB. Recordset ")
Rcs. open SQL, conn, 1, 1
Set Result = rcs
End Function
'*************************************** ****************************
'Dialog box
'*************************************** ****************************
Sub alert (message)
Message = replace (message ,"'","\'")
Response. Write ("<script> alert ('" & message & "') </script> ")
End Sub
'*************************************** ****************************
'Back to the previous page, generally used after determining whether the information is completely submitted
'*************************************** ****************************
Sub GoBack ()
Response. write ("<script> history. go (-1) </script> ")
End Sub
'*************************************** ****************************
'Redirect another connection
'*************************************** ****************************
Sub Go (url)
Response. write ("<script> location. href ('" & url & "') </script> ")
End Sub
'*************************************** ****************************
'Replace the html Tag
'*************************************** ****************************
Function htmlencode2 (str)
Dim result
Dim l
If isNULL (str) then
Htmlencode2 = ""
Exit function
End if
L = len (str)
Result = ""
Dim I
For I = 1 to l
Select case mid (str, I, 1)
Case "<"
Result = result + "<"
Case ">"
Result = result + ">"
Case chr (13)
Result = result + "<br>"
Case chr (34)
Result = result + """
Case "&"
Result = result + "&"
Case chr (32)
'Result = result + ""
If I + 1 <= l and I-1> 0 then
If mid (str, I + 1,1) = chr (32) or mid (str, I + 1,1) = chr (9) or mid (str, I-1, 1) = chr (32) or mid (str, I-1, 1) = chr (9) then
Result = result + ""
Else
Result = result + ""
End if
Else
Result = result + ""
End if
Case chr (9)
Result = result + ""
Case else
Result = result + mid (str, I, 1)
End select
Next
Htmlencode2 = result
End function
'*************************************** ****************************
'Check whether the SQL string contains single quotes. If yes, convert the string.
'*************************************** ****************************
Function CheckStr (str)
Dim tstr, l, I, ch
Str = Trim (str)
L = len (str)
For I = 1 to l
Ch = mid (str, I, 1)
If ch = "'" then
Tstr = tstr + "'"
End if
Tstr = tstr + ch
Next
CheckStr = tstr
End function
%>