当前位置: 首页 > 图文教程 > 网络编程 > ASP > 替换数据库内容

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 中的 替换数据库内容


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

<%
'####################################
'替换数据库内容 lamking 2005-8-22
'更新修正:2006-6-28
'http://www.imbbs.cn QQ:628557
'出售空间域名。网页制作。
'####################################
'以下请根据你的不同情况做修改
Const S1="admin" '要被替换的字符串
Const S2="1234" '替换为的字符串
Const Db="lamking.mdb" '数据库
Const IgnoreCase=True '忽略大小写
'以下数据无需更改
Dim oRs,oRs2,conn,I
Set conn=Server.CreateObject("Adodb.Connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&server.mappath(Db)
Set oRs=conn.OpenSchema(20)
Do While not oRs.Eof
If Ucase(oRs("TABLE_TYPE"))="TABLE" Then '如果是用户表
'循环替换该表的每一个字段
Set oRs2=Server.CreateObject("Adodb.RecordSet")
oRs2.Open "select * from ["&ors("TABLE_NAME")&"]",conn,1,3
Do While Not oRs2.Eof
For I=0 To oRs2.Fields.Count-1
'如果是OLE对象或者自动编号字段,则不替换
If oRs2(I).Properties("ISAUTOINCREMENT")=False And ors2(I).type<>205 Then
oRs2(oRs2(I).Name)=MyReplace(oRs2(I).value)
End If
Next
oRs2.update
oRs2.MoveNext
Loop
oRs2.close
set oRs2=Nothing
End If
oRs.Movenext
Loop
oRs.close
Set oRs=nothing
Conn.close
Set Conn=nothing
Response.Write"替换完成"

Function myreplace(byval Tstr)
Dim RegEx
If Tstr="" Or isnull(Tstr) Then Exit Function
Set RegEx=New RegExp
RegEx.Global = True
RegEx.IgnoreCase = IgnoreCase
RegEx.MultiLine = True
RegEx.Pattern=S1
myReplace=RegEx.Replace(TStr,S2)
Set RegEx=Nothing
End Function
%>