1. 安装Access数据库驱动 AccessDatabaseEngine.exe

  2. 下载ADO.au3 UDF

    这是为简化ADO操作封装的一些数据库操作接口

  3. 连接数据库

    1
    2
    3
    4
    5
    6
    7
    Local $driver = 'Microsoft Access Driver (*.mdb)'
    Local $dbname = @ScriptDir & '/xxx.mdb'
    Local $dbuser = ''
    Local $dbpassword = 'xxx'
    Local $sConnectionString = 'DRIVER=' & $driver & ';Dbq=' & $dbname & ';Uid=' & $dbuser & ';PWD=' & $dbpassword & ';'
    Local $oConnection = _ADO_Connection_Create()
    _ADO_Connection_OpenConString($oConnection, $sConnectionString)

    若是Microsoft Access 2007及以后的版本,driver要写成 ‘Microsoft Access Driver (*.mdb *.accdb)’

  4. 查询数据

    1
    2
    3
    $aQresult = _ADO_Execute($oConnection, "SELECT * FROM 表名", True)
    $Qresult = _ArrayToString($aQresult[2])
    ConsoleWrite("2 $Qresult " & $Qresult & @CRLF)
  5. 关闭数据库连接

    1
    2
    _ADO_Connection_Close($oConnection)
    $oConnection = null