<script>ec(2);</script> 这是我经常用的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
|