Common ASP Functions

Source: Internet
Author: User

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

%>

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.