替換資料庫內容

來源:互聯網
上載者:User

<%
'####################################
'替換資料庫內容 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
%>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.