当前位置: 首页 > 图文教程 > 网络编程 > ASP > Access通用-自动替换数据库中的字符串

ASP
用ASP编写网络传呼机
用ASP+CSS实现随机背景
ASP下载系统防盗链方法
用ASP编写下载网页中所有资源的程序
Request.ServerVariables应用
解决Asp程序的Server.CreateObject错误
ASP实现TCP端口扫描的方法
源码实例:ASP实现远程保存图片
用ASP+DLL实现WEB方式修改服务器时间
ASP使用MySQL数据库全攻略
ASP+SQL Server构建网页防火墙
教程/ASP 十天学会ASP之第二天
教程/ASP 十天学会ASP之第四天
教程/ASP 十天学会ASP之第五天
教程/ASP 十天学会ASP之第六天
教程/ASP 十天学会ASP之第七天
教程/ASP 十天学会ASP之第八天
教程/ASP 十天学会ASP之第九天
教程/ASP 十天学会ASP之第十天
关于学习ASP和编程的28个观点

ASP 中的 Access通用-自动替换数据库中的字符串


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 24 ::
收藏到网摘: n/a

       自己可以修改myreplace函数,实现复杂的替换.呵呵,好象用处不大.主要是看看如何读取access表和字段列表
  
  <%
  '####################################
  '替换数据库内容 lamking 2005-8-22
  'http://www.lamking.com QQ:628557
  '####################################
  Dim Db,Connstr,conn,rs,rs2,str1,str2,I
  str1="abcd" '要替换的字符串
  str2="1234" '替换为的字符串
  Db="lamking.mdb"
  Set conn=Server.CreateObject("ADODB.Connection")
  ConnStr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&server.mappath(Db)
  Conn.Open ConnStr
  Set rs = conn.OpenSchema(20)
   Do While Not rs.eof
   If rs("TABLE_TYPE")="TABLE" Then
   Set Rs2=Server.Createobject("adodb.recordset")
   Rs2.Open "select * from ["&rs("TABLE_NAME")&"]",conn,1,3
   Do While Not Rs2.Eof
   For I=0 to Rs2.fields.count-1
   If Rs2(i).Properties("ISAUTOINCREMENT") = False Then
   Rs2(Rs2(i).name)=Myreplace(Rs2(i).value)
   End If
   Next
   Rs2.Movenext
   Loop
   Rs2.Close
   Set Rs2=nothing
   End If
  Rs.Movenext
  Loop
  Rs.close
  Set Rs=nothing
  Conn.close
  Set Conn=nothing
  Response.Write"替换完成"
  Function myreplace(byval Tstr)
  If Tstr="" Or isnull(Tstr) Then
   Exit Function
  Else
   myReplace=replace(Tstr,str1,str2)
  End If
  End Function
  %>