教程集 www.jiaochengji.com
教程集 >  脚本编程  >  Asp  >  正文 asp数据连接库代码

asp数据连接库代码

发布时间:2016-10-13   编辑:jiaochengji.com
教程集为您提供asp数据连接库代码等资源,欢迎您收藏本站,我们将为您提供最新的asp数据连接库代码资源

这是我经常用的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.jiaochengji.com

您可能感兴趣的文章:
asp 全面安全数据连接代码
asp数据库连接代码
ASP设计常见问题及解答精要(2)
ASP 3.0高级编程(三十八)
asp 数据库连接代码与数据库关闭代码
掌握ASP其实只需要6步
asp数据连接函数与关闭
ASP与JSP的比较(二)
检测用户名是否存在
ASP连接SQL Server数据库程序代码

[关闭]
~ ~