Blois Posted August 23, 2018 Posted August 23, 2018 Hi Guys, Fine? I have this code and I use it to perform the query, however when I change the query to INSERT it is not working return error. expandcollapse popup#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) If @error then Return SetError(@error, @extended, 0) $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 $queryInsert = INSERT INTO TABLENAME VALUES (''aaaaa'', ''bbbbbb'', ''cccccc'') Local $aResult With $adoRs .CursorType = 2 .LockType = 3 .Open($queryInsert, $adoCon) If @error Then ; deal with Probable SQL error Return SetError(1) EndIf If Not .EOF Then $aResult = .GetRows() .Close() EndWith $adoRs = 0 _ArrayDisplay($aResult, 'UBound($aResult)=' & UBound($aResult)) For $iRow_idx = 0 To UBound($aResult) - 1 GUICtrlCreateListViewItem($aResult[$iRow_idx][0], $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 Help, Please!
Earthshine Posted August 23, 2018 Posted August 23, 2018 does your query work in access? My resources are limited. You must ask the right questions
FrancescoDiMuro Posted August 23, 2018 Posted August 23, 2018 @Blois Seems ( at least from the code you posted ), that you are missing some double quotes in your query definition. $queryInsert = INSERT INTO TABLENAME VALUES (''aaaaa'', ''bbbbbb'', ''cccccc'') Should be: $queryInsert = "INSERT INTO TABLENAME VALUES ('aaaaa', 'bbbbbb', 'cccccc');" What kind of error does AutoIt return? Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
Blois Posted August 24, 2018 Author Posted August 24, 2018 (edited) 5 hours ago, Earthshine said: does your query work in access? @Earthshine Yes, work! $querySelect = 'Select * From TABLE' Edited August 24, 2018 by Blois
FrancescoDiMuro Posted August 24, 2018 Posted August 24, 2018 @Blois The script is telling you that the number of fields you are inserting in the table is not the same of the number of fields you do have in your table. What's your table schema, and which real values are you trying to insert into it? Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
Blois Posted August 24, 2018 Author Posted August 24, 2018 7 hours ago, FrancescoDiMuro said: @Blois The script is telling you that the number of fields you are inserting in the table is not the same of the number of fields you do have in your table. What's your table schema, and which real values are you trying to insert into it? @FrancescoDiMuro Thank you!I had forgotten that I put a self-numbered Column.
FrancescoDiMuro Posted August 24, 2018 Posted August 24, 2018 @Blois Happy to have helped Blois 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
Blois Posted August 27, 2018 Author Posted August 27, 2018 @FrancescoDiMuro In the test file where only the insert code works, but when I paste the code in .au3 the GUI gives an error that does not find the database.
FrancescoDiMuro Posted August 27, 2018 Posted August 27, 2018 @Blois What is your Connection String on AutoIt? Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
Blois Posted August 27, 2018 Author Posted August 27, 2018 (edited) 1 hour ago, FrancescoDiMuro said: @Blois What is your Connection String on AutoIt? These errors stopped when I used the only $adoCon.Open("Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & $dbname & ";Uid=;Pwd=;") Now I have this error: line error: If Not .EOF Then $aResult = .GetRows() Edited August 27, 2018 by Blois
Blois Posted August 27, 2018 Author Posted August 27, 2018 @FrancescoDiMuro I'm sorry, I was closing the connection before capturing the result.Machines without Access can not connect to the MDB, is there anything that can be done?
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now