ASP常用的函数
程序员文章站
2022-04-14 20:33:11
asp常用的函数,希望能用的着。
<%
dim db
db="dbms.mdb"
'************************...
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
%>
<%
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
%>
上一篇: 一份针对于新手的多线程实践--进阶篇
下一篇: [十六]基础类型BigInteger简介