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
%>