加入收藏 | 设为首页 | 会员中心 | 我要投稿 聊城站长网 (https://www.0635zz.com/)- 智能语音交互、行业智能、AI应用、云计算、5G!
当前位置: 首页 > 站长学院 > Asp教程 > 正文

ASP常用的函数有什么呢?

发布时间:2023-08-17 14:28:12 所属栏目:Asp教程 来源:
导读:在ASP中,一段带有返回值的代码被称为函数,我们可以通过编写一段代码来计算自然数是否是质数,然后再返回到调用程序,今天错新技术频道将和你分享ASP常用的函数有那些?小编将为你细细道来。

<%

dim db
在ASP中,一段带有返回值的代码被称为函数,我们可以通过编写一段代码来计算自然数是否是质数,然后再返回到调用程序,今天错新技术频道将和你分享ASP常用的函数有那些?小编将为你细细道来。
 
<%
 
dim db
 
db="dbms.mdb"
 
'******************************************************************
 
'执行sql语句,不返回值,sql语句最好是如下:
 
'update 表名 set 字段名=value,字段名=value where 字段名=value
 
'delete from 表名 where 字段名=value
 
'insert into 表名 (字段名,字段名) 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
 
'*******************************************************************
 
'执行select语句,返回recordset对象。该对象只读。也就是不能更新
 
'*******************************************************************
 
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
 
'*******************************************************************
 
' 弹出对话框
 
'*******************************************************************
 
Sub alert(message)
 
message = replace(message,"'","/'")
 
Response.Write ("<script>alert('" & message & "')</script>")
 
End Sub
 
'*******************************************************************
 
' 返回上一页,一般用在判断信息提交是否完全之后
 
'*******************************************************************
 
Sub GoBack()
 
Response.write ("<script>history.go(-1)</script>")
 
End Sub
 
'*******************************************************************
 
' 重定向另外的连接
 
'*******************************************************************
 
Sub Go(url)
 
Response.write ("<script>location.href('" & url & "')</script>")
 
End Sub
 
'*******************************************************************
 
' 把html标记替换
 
'*******************************************************************
 
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
 
'*******************************************************************
 
' 检查sql字符串中是否有单引号,有则进行转化
 
'*******************************************************************
 
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
 
%>
 
 

(编辑:聊城站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章