RSS
热门关键字:  下载  cms  模版  开源  dedecms
当前位置 :| 主页 > 站长学院 > ASP/VbScript >

删除不规则或不必要的Email地址(数据库)

来源:互联网 作者:未知 时间:2002-09-13 Tag: 点击:
A nifty script to delete unwanted or invalid Email addresses from a database. Works with Access mdb and SQL Server databases. No config required, ready to use. Can be used for cleaning up any other unwanted records as well.  Code: ASP 3.0 & VBScript


<%@Language="vbscript" %>
<%
'****************************************************************************
' This script deletes all unwanted Email addresses from a database          
' in multiple tables                                                        
' Note: Change the field name EMail to your fields name.....                
' Written on: 09.03.2001 by: Cenk Yurtseven                                  
' www.asprobots.com, info@asprobots.com                                      
'****************************************************************************
Const adOpenForwardOnly = 0
Const adLockReadOnly = 1
Const adCmdText = &H0001
Const adUseClient = 3
If Request.QueryString("md") = "dl" And Request.Form("sAddress") <> "" And Request.Form("dbName") <> "" Then
      DSNName = Request.Form("dbName") & ".mdb"
      Set Con = Server.CreateObject("ADODB.Connection")
      Con.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath(DSNName)
      strAddresses = Request.Form("sAddress")
      splitAddress = Split(strAddresses, ",")
      Set Table = Con.OpenSchema (20)
      Do While Not Table.EOF
            TblName = Table("Table_Name")
            'The condition below excludes the system tables from beeing processed
            If UCase(Left(TblName,4)) <> "MSYS" And UCase(Left(TblName,3)) <> "SYS" And UCase(Left(TblName,4)) <> "RTBL" Then
                  strSQL = "SELECT * FROM " & TblName
                  Set rs = Server.CreateObject("ADODB.Recordset")
                  rs.CursorLocation = adUseClient
                  rs.Open (strSQL), Con, adOpenForwardOnly, adLockReadOnly, adCmdText
                  For Each fldName In rs.Fields
                        If fldName.Name = "EMail" Then
                              For i = 0 To UBound(splitAddress)
                                    oneAddress = Trim(splitAddress(i))
                                    strSQL = "DELETE FROM " & TblName & " WHERE EMail = '" & oneAddress & "'"
                                    Con.Execute(strSQL)
                              Next
                        End If
                  Next
                  rs.Close
                  Set rs = Nothing
            End If
            Table.MoveNext
      Loop
      Con.Close
      Set Con = Nothing
End If
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Delete Multiple Addresses</TITLE>
</HEAD>
<BASEFONT FACE="Verdana">
<BODY BGCOLOR="#000080" TEXT="#FFFFFF">
<BR>
<DIV ALIGN="center"><B>Delete Multiple Addresses</B>
<FORM ACTION="deladdre.asp?md=dl" METHOD="post">Database Name:
<INPUT TYPE="text" NAME="dbName" STYLE="text-align: right"><B>.mdb</B>
<BR>
<BR>Paste all unwanted addresses into the textarea below, separated by a comma<B>,</B>
<BR>
<TEXTAREA COLS="80" ROWS="8" NAME="sAddress"></TEXTAREA>
<INPUT TYPE="submit" VALUE="Delete Addresses"></FORM>
<SMALL><B>Note:</B> This action will delete the selected addresses from all tables of the selected database.</SMALL>
<BR>
<BR>This file must be located in the same folder of the database.</DIV>
</BODY>
</HTML>

最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册
热点关注
相关文章