|
|
ASP+ACCESS字符串查找替换工具
功能:
用asp脚本批量替换access数据库中指定字段内指定字符串
1:使用该工具替换之时建议勾选备份数据库功能选项,备份好你的数据库,以免出错!
2:本程序适合ASP+ACCESS版本的网站程序,SQL版本不适用。
3:必须完整填写所有的表单,才能够顺利替换内容。
4:程序经过严格的测试完美无错。
5:使用完该程序以后,建议从服务器删除该文件,以免被恶意利用!
源代码如下:
- <head>
- <title>ASP字符串查找替换工具</title>
- </head>
- <style type="text/css">
- <!--
- body,td,th {
- font-size: 12px;
- color: #000000;
- }
- body {
- background-color: #FFFFFF;
- }
- a {
- font-size: 12px;
- color: #0000CC;
- }
- A:link {
- TEXT-DECORATION: none
- }
- a:visited {
- color: #FF0000;TEXT-DECORATION: none
- }
- .STYLE1 {
- color: #FFFFFF;
- font-size: 36px;
- }
- .STYLE2 {color: #FF0000}
- -->
- </style>
- <script language=JavaScript>
- function check(theform)
- {
-
- if (theform.datapath.value=="")
- {
- alert("请正确填写数据库路径!");
- theform.datapath.focus();
- return(false);
- }
- else if (theform.tablename.value=="")
- {
- alert("请正确填写表单名字!");
- theform.tablename.focus();
- return(false);
- }
- else if (theform.fieldname.value=="")
- {
- alert("请正确填写字段名字!");
- theform.fieldname.focus();
- return(false);
- }
- else if (theform.keyword1.value=="")
- {
- alert("请输入要查找的关键字!");
- theform.keyword1.focus();
- return(false);
- }
- else if (theform.keyword2.value=="")
- {
- alert("请输入要替换的关键字!");
- theform.keyword2.focus();
- return(false);
- }
- }
- </script>
- <div align=center top="0">
- <table border="1" width="54%" id="table1" cellspacing="1" bordercolor="#000000" style="border-collapse: collapse">
- <form name="replace" method="post" action="replace.asp?action=update" onsubmit="return check(this);">
- <tr>
- <td colspan="2" bgcolor="#003366">
- <p align="center"><b><font size="5" color="#FFFFFF">ASP字符串查找替换工具</font></b></td>
- </tr>
- <tr>
- <td width="93%" height="20" colspan="2" bgcolor="#D0E8FF">1:使用该工具替换之时建议勾选备份数据库功能选项,备份好你的数据库,以免出错!<br>
- 2:本程序适合ASP+ACCESS版本的网站程序,SQL版本不适用。<br>3:必须完整填写所有的表单,才能够顺利替换内容。<br>4:程序经过严格的测试完美无错,如有问题,欢迎光临我的博客和我交流!<br>5:使用完该程序以后,建议从服务器删除该文件,以免被恶意利用!</td>
- </tr>
- <tr>
- <td width="17%" height="20" align="right" bgcolor="#FFE8F3">数据库路径:</td>
- <td width="73%" height="20" bgcolor="#FFE8F3">
- <input type="text" name="datapath" size="20" value="<%if request.cookies("datapath")<>"" then
- response.write request.cookies("datapath")
- end if%>">
- 如:database/data.mdb【请填写相对路径!】</td>
- </tr>
- <tr>
- <td width="17%" height="20" align="right" bgcolor="#FFE8F3">表单名字:</td>
- <td width="73%" height="20" bgcolor="#FFE8F3">
- <input type="text" name="tablename" size="20" value="<%if request.cookies("tablename")<>"" then
- response.write request.cookies("tablename")
- end if%>">
- 如:webuser【ACCESS保留名字如:user不用加中括号!】</td>
- </tr>
- <tr>
- <td width="17%" height="20" align="right" bgcolor="#FFE8F3">字段名字:</td>
- <td width="73%" height="20" bgcolor="#FFE8F3">
- <input type="text" name="fieldname" size="20" value="<%if request.cookies("fieldname")<>"" then
- response.write request.cookies("fieldname")
- end if%>">
- 如:username【ACCESS保留名字如:user不用加中括号!】</td>
- </tr>
- <tr>
- <td width="17%" height="20" align="right" bgcolor="#FFE8F3">查找内容:</td>
- <td width="73%" height="20" bgcolor="#FFE8F3">
- <input type="text" name="keyword1" id="keyword1" size="20" value="<%if request.cookies("key1")<>"" then
- response.write request.cookies("key1")
- end if%>">
- 如:兄弟</td>
- </tr>
- <tr>
- <td width="17%" height="20" align="right" bgcolor="#FFE8F3">替 换 成:</td>
- <td width="73%" height="20" bgcolor="#FFE8F3">
- <input type="text" name="keyword2" id="keyword2" size="20" value="<%if request.cookies("key2")<>"" then
- response.write request.cookies("key2")
- end if%>">
- 如:好兄弟【如替换成空,请按一下空格键】</td>
- </tr>
- <tr>
- <td width="93%" height="20" align="right" bgcolor="#FFE8F3" colspan="2">
- <p align="center"><input type=checkbox name="backcheck" value="1">备份数据库 <input class=input2 name=B2 type=reset value="重填"> <input name="Submit" type="Submit" id="Submit" value="替换"> <a href="?action=delcookies">清空COOKIES记录</a></td>
- </tr>
- <tr>
- <td width="93%" height="22" align="right" bgcolor="#003366" colspan="2">
- <p align="center"><font color="#FFFFFF" size="3"><b>Copyright 2010-2012
- @ <a href="http://www.030904.com/blog/default.asp">
- <font color="#FFFFFF" size="3">兄弟的博客</font></a></b></font></td>
- </tr>
- </form>
- </table></div>
- <%if request("action")="update" then%>
- <%
- Function CheckDir(FolderPath)
- dim fso1
- folderpath=Server.MapPath(".")&""&folderpath
- Set fso1 = Server.CreateObject("Scripting.FileSystemObject")
- If fso1.FolderExists(FolderPath) then
- CheckDir = True
- Else
- CheckDir = False
- End if
- Set fso1 = nothing
- End Function
- Server.ScriptTimeout=9999999
- Dim datapath,tablename,fieldname,Conn,rs,sql,key1,key2,backcheck
- backcheck=request.form("backcheck")
- datapath=request.form("datapath")
- If backcheck="1" then
- bkfolder=left(datapath,InstrRev(datapath,"/")-1)
- Dim DateYear,DateMonth,DateDay,DateHour,DateMinute,DateSecond
- dbpath=server.mappath(datapath)
- DateYear=Year(Now())
- DateMonth=Month(Now())
- DateDay=Day(Now())
- DateHour=Hour(Now())
- DateMinute=Minute(Now())
- DateSecond=Second(Now())
- If Len(DateMonth)<2 Then DateMonth="0"&DateMonth
- If Len(DateDay)<2 Then DateDay="0"&DateDay
- If Len(DateHour)<2 Then DateHour="0"&DateHour
- If Len(DateMinute)<2 Then DateMinute="0"&DateMinute
- If Len(DateSecond)<2 Then DateSecond="0"&DateSecond
- bkdbname=DateYear&DateMonth&DateDay&DateHour&DateMinute&DateSecond
- Set Fso=server.createobject("scripting.filesystemobject")
- If fso.fileexists(dbpath) then
- If CheckDir(bkfolder) = True Then
- fso.copyfile dbpath,bkfolder& ""& bkdbname &".asp"
- End if
- End if
- End if
- tablename=request.form("tablename")
- fieldname=request.form("fieldname")
- key1=request.form("keyword1")
- key2=request.form("keyword2")
- Response.cookies("datapath")=datapath
- Response.cookies("tablename")=tablename
- Response.cookies("fieldname")=fieldname
- Response.cookies("key1")=key1
- Response.cookies("key2")=key2
- If datapath="" or tablename="" or fieldname="" or key1="" or key2="" then
- response.write"<SCRIPT language=JavaScript>alert('对不起!你的数据没有填写完整!');"
- response.write"javascript:location.href='replace.asp';</SCRIPT>"
- else
- Set Conn = Server.CreateObject("ADODB.Connection")
- Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(datapath)
- Set rs = Server.Createobject("ADODB.Recordset")
- sql="Select * from ["&tablename&"] where "&fieldname&" like '%"&key1&"%'"
- rs.open sql,conn,1,3
- while not rs.eof
- rs(""&fieldname&"")=replace(rs(""&fieldname&""),key1,key2)
- rs.update
- rs.movenext
- wend
- rs.close
- set rs=nothing
- conn.close
- set conn=nothing
- response.write"<SCRIPT language=JavaScript>alert('恭喜你!数据替换成功!');"
- response.write"javascript:location.href='replace.asp';</SCRIPT>"
- end if
- %>
- <%end if%>
- <%
- if request("action")="delcookies" then
- Response.cookies("datapath")=""
- Response.cookies("tablename")=""
- Response.cookies("fieldname")=""
- Response.cookies("key1")=""
- Response.cookies("key2")=""
- response.write"<SCRIPT language=JavaScript>alert('恭喜你!清理COOKIES记录成功!');"
- response.write"javascript:location.href='replace.asp';</SCRIPT>"
- end if
- %>
复制代码
成品如下:
ASP字符串查找替换工具:
https://545c.com/file/4000752-427250156
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|