In ASP, a piece of code with a return value is called a function. We can write a piece of code to calculate whether a natural number is a prime number, and then return to the calling program. Today, the new technology channel will share with you what are the commonly used functions of ASP? The editor will explain it to you in detail.
<%
dim db
db="dbms.mdb"
'************************************************************************
'Execute the SQL statement without returning the value. The best SQL statement is 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.execute 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
'*********************************************************************************
' The dialog box pops up
'*********************************************************************************
Sub alert(message)
message = replace(message,"'","/'")
Response.Write ("<script>alert('" & message & "')</script>")
End Sub
'*********************************************************************************
' Return to the previous page, usually used after judging whether the information is submitted completely
'*********************************************************************************
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 there are single quotes in the sql string, and if there is, convert it
'*********************************************************************************
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
%>
What are the common functions used in ASP introduced by the New Technology Channel in today’s article? I believe that through the introduction above, everyone has learned it thoroughly, but it still needs to review it to consolidate this knowledge.