vb批量修改access数据库
公司给个任务,在某个路径下,所有.abc为后缀文件名为ACCESS数据库的文件,默认有一行hello的用户的记录,密码是123123123,批量把这行记录拿掉。
记录一下,以后省得再弄,不太懂vb弄了个灰头土脸,再回头看看以前那公司的所谓的维护网管,真不懂他们能“维护”什么东西,无论是windows还是linux在我看来。
- Dim objFSO
- Dim ofolder
- Dim objStream
- Dim strSearch
- Dim strfolderSearch
- Set objFSO = CreateObject("scripting.filesystemobject")
- Set objStream = objFSO.createtextfile("c:\resolved.txt", True)
- strfolderSearch = "E:\wwwroot"
- strSearch = ".abc"
- strLen=Len(strSearch)
- CheckFolder (objFSO.getfolder(strfolderSearch)), objStream
- MsgBox "File Search Completed." + vbCr + "Please check c:\resolved.txt for details."
- Sub CheckFolder(objCurrentFolder, objtxtFile)
- On Error Resume Next
- Dim strTemp
- Dim strOutput
- Dim objNewFolder
- Dim objFile
- Dim objStream
- For Each objFile In objCurrentFolder.Files
- strTemp = Right(objFile.Name, strLen)
- If UCase(strTemp) = UCase(strSearch) Then
- objtxtFile.writeline CStr(objFile.Path)
- Dim Conn,SQL
- Dim dbPath,Password
- Set conn = CreateObject("ADODB.Connection")
- dbPath=objFile.Path
- Password="123123123"
- Conn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ="&dbPath&";User ID="¶m_dbUserID&";Password="&Password
- If Err Then
- objtxtFile.writeline CStr(objFile.Path) + "-----------" + err.tostring + "----------Failed !"
- Err.CLEAR
- Set Conn = NOTHING
- Else
- Set RS = Conn.Execute("Select * From admin Where name='hello'")
- If RS.recordcount > 0 Then
- Conn.Execute("Delete From admin Where name='hello'")
- End If
- Conn.close
- End if
- End If
- Next
- For Each objNewFolder In objCurrentFolder.subFolders
- CheckFolder objNewFolder, objtxtFile
- Next
- End Sub