Try this:
#include <GUIConstants.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>
Global $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")
Example()
Func Example()
Local $dbname = FileOpenDialog("Choose Access Database", @ScriptDir, "Access files (*.accdb)", 1)
$adoCon = ObjCreate("ADODB.Connection")
$adoCon.Open("Driver={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ=" & $dbname & ";Uid=;Pwd=;")
$adoRs = ObjCreate("ADODB.Recordset")
GUICreate("listview items", 550, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
Local $idListview = GUICtrlCreateListView("Codigo |Nome |Valor ", 10, 10, 520, 150) ;,$LVS_SORTDESCENDING
$query = 'SELECT "codigo" , "nome" , "valor" FROM Produtos1 WHERE codigo < 10'
Local $sResult = ''
With $adoRs
.CursorType = 2
.LockType = 3
.Open($query, $adoCon)
If @error Then
; deal with Probable SQL error
Return SetError(1)
EndIf
If Not .EOF Then $sResult = .GetString(2, -1, '|', '~?~')
.Close()
EndWith
$adoRs = 0
Local $aResult = StringSplit($sResult, '~?~', $STR_ENTIRESPLIT + $STR_NOCOUNT)
For $iRow_idx = 0 To UBound($aResult) - 1
GUICtrlCreateListViewItem($aResult[$iRow_idx], $idListview)
Next
$adoCon.Close
GUISetState()
; Loop until the user exits.
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
;~ Case $idButton
;~ MsgBox($MB_SYSTEMMODAL, "listview item", GUICtrlRead(GUICtrlRead($idListview)), 2)
Case $idListview
MsgBox($MB_SYSTEMMODAL, "listview", "clicked=" & GUICtrlGetState($idListview), 2)
EndSwitch
WEnd
EndFunc ;==>Example
; User's COM error function. Will be called if COM error occurs
Func _ErrFunc($oError)
; Do anything here.
ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
@TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
@TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
@TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
@TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
@TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
@TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
@TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
@TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
@TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc ;==>_ErrFunc