asp+access generic Automatic Replacement database string _ Application Tips

Source: Internet
Author: User

Originally just to play to write, did not expect to write after the constant questioning, so rewrite the code, perfect a bit, support the regular replacement, avoid the cause of the error of the binary (OLE object), and made an EXE program. Thanks for virtual help.
Attached ASP code:

Copy Code code as follows:

<%
'####################################
' Bulk Replace database contents 2008-3-17
' Replacement is irreversible, so make it back before operation
'####################################
Dim Db,conn,rs1,rs2,str1,str2,i,re
Str1= "admi[0-z]" ' String to replace, support regular
str2= "1234" replaced with a string
db= "Db.mdb" ' Database address
' The following need not be changed
' Create a regular object
Set re=new REGEXP
Re.ignorecase =true
Re.global=true
Set conn=server.createobject ("ADODB. Connection ")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" &server.mappath (Db)
Set Rs1 = Conn.openschema (20)
Do as not rs1.eof
If UCase (Rs1 ("Table_type")) = "Table" Then ' if it is a user table, action
Set rs2=server.createobject ("Adodb.recordset")
Rs2.open "SELECT * FROM [" &AMP;RS1 ("table_name") "]", conn,1,3
Do as not rs2.eof
For i=0 to Rs2.fields.count-1 ' traverse all fields
If Rs2 (i). Properties ("isautoincrement") = False and Rs2 (i). type<>128 and Rs2 (i). type<>204 and Rs2 (i). type<>205 Then ' if not automatically numbered and not OLE object
RS2 (Rs2 (i). Name) =myreplace (RS2 (i) .value& "")
End If
Next
Rs2.movenext
Loop
Rs2.close
Set rs2=nothing
End If
Rs1.movenext
Loop
Rs1.close
Set rs1=nothing
Conn.close
Set conn=nothing
Set re=nothing
Response.Write "Replace Complete"

' Custom substitution function
Function Myreplace (ByVal tstr)
If tstr= "" Or isnull (TSTR) Then
Exit Function
Else
Re.pattern=str1
Myreplace =re.replace (TSTR,STR2)
End If
End Function
%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.