這是我經常用的asp資料庫連接代碼,拿出來當然不是為了什麼嘍,只希望給初學者一些協助,因為我記得我剛學時這個串連也搞一半天時間啊.
<%
Dim Rs,Conn//這裡申明一下,必須在函數或過程外面申明,要不然會定義無效,原因是變數的全域和私人變數的原因了.
Sub Db_connect()//建立串連
Dpath ="data\db1.mdb"
Set Conn=Server.CreateObject("Adodb.connection")
Set Rs =Server.CreateObject("Adodb.Recordset")
Conn.connectionstring="Provider=Microsoft.Jet.oledb.4.0;Data source="&Server.MapPath(Dpath)
Conn.open
End sub
sub closedb()//關閉串連
if isobject(Rs) then
if not(Rs is nothing) then
Rs.close
set Rs=nothing
end if
end if
if isobject(Conn) then
if not(Conn is nothing) then
Conn.close
set Conn=nothing
end if
end if
end sub
'*********************************************************
function html_encode(html)//這裡是進行基本的過濾函數,這個可以把textarea裡面的斷行符號替換成換行
dim temp
temp=replace(html,"<","<")
temp=replace(temp,">",">")
temp=replace(temp,"'","單引號")
temp=replace(temp,chr(13),"<br>")
html_encode=replace(temp,chr(32)," ")
end function
function encode_html(html)//這個剛好和上面個函數相反還原資料.
dim temp
temp=replace(html,"<","<")
temp=replace(temp,">",">")
temp=replace(temp,"單引號","'")
temp=replace(temp,chr(13),"<br>")
encode_html=replace(temp,chr(32)," ")
end function
%>
本站原創轉載請注:www.111cn.net