ASP新手之常用源代码的总结(下)
创始人
2024-08-02 18:31:50
0

ASP是Active Server Page的缩写,意为“动态服务器页面”。ASP是微软公司开发的代替CGI脚本程序的一种应用,它可以与数据库和其它程序进行交互,是一种简单、方便的编程工具。接上篇>>

11.ACCESS数据库连接:

  1. <%   
  2. option explicit   
  3. dim startime,endtime,conn,connstr,db   
  4. startime=timer()   
  5. '更改数据库名字   
  6. db="data/dvBBS5.mdb"   
  7. Set conn = Server.CreateObject("ADODB.Connection")   
  8. connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(db)   
  9. '如果你的服务器采用较老版本Access驱动,请用下面连接方法   
  10. 'connstr="driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath(db)   
  11. conn.Open connstr   
  12. function CloseDatabase   
  13. Conn.close   
  14. Set conn = Nothing   
  15. End Function   
  16. %> 

12.SQL数据库连接:

  1. <%   
  2. option explicit   
  3. dim startime,endtime,conn,connstr,db   
  4. startime=timer()   
  5. connstr="driver={SQL Server};server=HUDENQ-N11T33NB;uid=sa;pwd=xsfeihu;database=dvbbs"   
  6. Set conn = Server.CreateObject("ADODB.Connection")   
  7. conn.Open connstr   
  8. function CloseDatabase   
  9. Conn.close   
  10. Set conn = Nothing   
  11. End Function   
  12. %> 

13.用键盘打开网页代码: 

  1.    
  2. function ctlent(eventobject)   
  3. {   
  4. if((event.ctrlKey && window.event.keyCode==13)||(event.altKey && window.event.keyCode==83))   
  5. {   
  6. window.open('网址','','')   
  7. }   
  8. }   
  9.  

这里是Ctrl+Enter和Alt+S的代码 自己查下键盘的ASCII码再换就行

14.让层不被控件复盖代码:

 # 前面   
  •  # 后面   
  •    
  •  

    15.动网FLASH广告代码:

    1. codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0
    2.  width="468" height="60"> 
    3.  
    4.  
    5. pluginspage=http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash;
    6. ;;;;;;;;;;; type="application/x-shockwave-flash" width="468" height="60">  

    16.VBS弹出窗口小代码:

    1.    
    2. msgbox"你还没有注册或登陆论坛","0","精品论坛"   
    3. location.href = "login.asp"   
    4.  

    17.使用FSO修改文件特定内容的函数:

     

    1. function FSOchange(filename,Target,String)   
    2. Dim objFSO,objCountFile,FiletempData   
    3. Set objFSO = Server.CreateObject("Scripting.FileSystemObject")   
    4. Set objCountFile = objFSO.OpenTextFile(Server.MapPath(filename),1,True)   
    5. FiletempData = objCountFile.ReadAll   
    6. objCountFile.Close   
    7. FiletempData=Replace(FiletempData,Target,String)   
    8. Set objCountFile=objFSO.CreateTextFile(Server.MapPath(filename),True)   
    9. objCountFile.Write FiletempData   
    10. objCountFile.Close   
    11. Set objCountFile=Nothing   
    12. Set objFSO = Nothing   
    13. End Function 

     

    18.使用FSO读取文件内容的函数:

     

    1. function FSOFileRead(filename)   
    2. Dim objFSO,objCountFile,FiletempData   
    3. Set objFSO = Server.CreateObject("Scripting.FileSystemObject")   
    4. Set objCountFile = objFSO.OpenTextFile(Server.MapPath(filename),1,True)   
    5. FSOFileRead = objCountFile.ReadAll   
    6. objCountFile.Close   
    7. Set objCountFile=Nothing   
    8. Set objFSO = Nothing   
    9. End Function 

     

    19.使用FSO读取文件某一行的函数:

     

    1. function FSOlinedit(filename,lineNum)   
    2. if linenum < 1 then exit function   
    3. dim fso,f,temparray,tempcnt   
    4. set fso = server.CreateObject("scripting.filesystemobject")   
    5. if not fso.fileExists(server.mappath(filename)) then exit function   
    6. set f = fso.opentextfile(server.mappath(filename),1)   
    7. if not f.AtEndofStream then   
    8. tempcnt = f.readall   
    9. f.close   
    10. set f = nothing   
    11. temparray = split(tempcnt,chr(13)&chr(10))   
    12. if lineNum>ubound(temparray)+1 then   
    13. exit function   
    14. else   
    15. FSOlinedit = temparray(lineNum-1)   
    16. end if   
    17. end if   
    18. end function 

    20.使用FSO修改文件特定内容的函数:

     

    1. function FSOchange(filename,Target,String)   
    2. Dim objFSO,objCountFile,FiletempData   
    3. Set objFSO = Server.CreateObject("Scripting.FileSystemObject")   
    4. Set objCountFile = objFSO.OpenTextFile(Server.MapPath(filename),1,True)   
    5. FiletempData = objCountFile.ReadAll   
    6. objCountFile.Close   
    7. FiletempData=Replace(FiletempData,Target,String)   
    8. Set objCountFile=objFSO.CreateTextFile(Server.MapPath(filename),True)   
    9. objCountFile.Write FiletempData   
    10. objCountFile.Close   
    11. Set objCountFile=Nothing   
    12. Set objFSO = Nothing   
    13. End Function 

     

    21.使用FSO读取文件内容的函数:

     

    1. function FSOFileRead(filename)   
    2. Dim objFSO,objCountFile,FiletempData   
    3. Set objFSO = Server.CreateObject("Scripting.FileSystemObject")   
    4. Set objCountFile = objFSO.OpenTextFile(Server.MapPath(filename),1,True)   
    5. FSOFileRead = objCountFile.ReadAll   
    6. objCountFile.Close   
    7. Set objCountFile=Nothing   
    8. Set objFSO = Nothing   
    9. End Function 

     

    22.使用FSO读取文件某一行的函数:

     

    1. function FSOlinedit(filename,lineNum)   
    2. if linenum < 1 then exit function   
    3. dim fso,f,temparray,tempcnt   
    4. set fso = server.CreateObject("scripting.filesystemobject")   
    5. if not fso.fileExists(server.mappath(filename)) then exit function   
    6. set f = fso.opentextfile(server.mappath(filename),1)   
    7. if not f.AtEndofStream then   
    8. tempcnt = f.readall   
    9. f.close   
    10. set f = nothing   
    11. temparray = split(tempcnt,chr(13)&chr(10))   
    12. if lineNum>ubound(temparray)+1 then   
    13. exit function   
    14. else   
    15. FSOlinedit = temparray(lineNum-1)   
    16. end if   
    17. end if   
    18. end function 

     

    到此,关于ASP常用代码的总结篇,就为大家介绍完了。希望对大家有帮助。

    【编辑推荐】

    1. ASP.NET的HTTP模块和处理程序之对话状态
    2. ASP.NET配置文件Web.config详细解释
    3. 使用gettext技术为ASP.NET网站实现国际化支持
    4. 大型高性能ASP.NET系统架构设计
    5. 详解ASP.NET MVC 3中View的变化

    相关内容

    热门资讯

    如何允许远程连接到MySQL数... [[277004]]【51CTO.com快译】默认情况下,MySQL服务器仅侦听来自localhos...
    如何利用交换机和端口设置来管理... 在网络管理中,总是有些人让管理员头疼。下面我们就将介绍一下一个网管员利用交换机以及端口设置等来进行D...
    施耐德电气数据中心整体解决方案... 近日,全球能效管理专家施耐德电气正式启动大型体验活动“能效中国行——2012卡车巡展”,作为该活动的...
    Windows恶意软件20年“... 在Windows的早期年代,病毒游走于系统之间,偶尔删除文件(但被删除的文件几乎都是可恢复的),并弹...
    20个非常棒的扁平设计免费资源 Apple设备的平面图标PSD免费平板UI 平板UI套件24平图标Freen平板UI套件PSD径向平...
    德国电信门户网站可实时显示全球... 德国电信周三推出一个门户网站,直观地实时提供其安装在全球各地的传感器网络检测到的网络攻击状况。该网站...
    着眼MAC地址,解救无法享受D... 在安装了DHCP服务器的局域网环境中,每一台工作站在上网之前,都要先从DHCP服务器那里享受到地址动...
    为啥国人偏爱 Mybatis,... 关于 SQL 和 ORM 的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行...