asp資料連線庫代碼

來源:互聯網
上載者:User

這是我經常用的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,"<","&lt;")
  temp=replace(temp,">","&gt;")
  temp=replace(temp,"'","單引號")
  temp=replace(temp,chr(13),"<br>")
  html_encode=replace(temp,chr(32),"&nbsp;")
 end function
 
 function encode_html(html)//這個剛好和上面個函數相反還原資料.

dim temp
  temp=replace(html,"&lt;","<")
  temp=replace(temp,"&gt;",">")
  temp=replace(temp,"單引號","'")
  temp=replace(temp,chr(13),"<br>")
  encode_html=replace(temp,chr(32),"&nbsp;")
 end function
%>

本站原創轉載請注:www.111cn.net

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.