price98 Posted October 30, 2018 Posted October 30, 2018 hi, I have add files to MS Access. Previously one of member of this forum help me upto here. In the below file, Its adding only text of file name. But i have to add whole file. Can anyone help me? gui.au3 Database4.accdb
Earthshine Posted October 30, 2018 Posted October 30, 2018 You need to learn some SQL My resources are limited. You must ask the right questions
Moderators JLogan3o13 Posted October 30, 2018 Moderators Posted October 30, 2018 3 hours ago, Earthshine said: You need to learn some SQL Does this truly strike you as helpful? "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Zedna Posted October 30, 2018 Posted October 30, 2018 Post TXT file with few lines of data and SQL syntax of your DB table (CREATE TABLE ...) Resources UDF ResourcesEx UDF AutoIt Forum Search
Earthshine Posted October 30, 2018 Posted October 30, 2018 i looked at the db... here, it's just field numbers. here is the exported data 1,"test.txt","Controller","Simulation","Testing" 2,"test1.txt",,"Testing", 3,"test2.txt","Simulation",,"Testing" 4,"test3.txt",,, 5,"test4.txt",,"Testing","Simulation" 6,"test5.txt","Testing",, 7,"test6.txt","Simulation",, 8,"test7.txt",,,"Testing" 9,"test8.txt","Simulation","Controller", 10,"test9.txt","Testing",, 11,"test10.txt",,"Testing", 12,"bhanu.txt",,, 13,"Test3.txt",,,"Testing" 14,"access.txt",,"Simulation", 15,"Test12.txt","Controller",, 16,"Test13.txt","Controller",,"Testing" 17,"Test14.txt",,"Simulation","Testing" 18,"Test15.txt",,,"Testing" 19,"Test16.txt","Controller","Simulation","Testing" 20,"Test17.txt","Controller",, 21,"Test18.txt",,"Simulation", 22,"Test19.txt","Controller",,"Testing" 23,"Test20.txt","Controller","Simulation","Testing" 24,"Test21.txt",,"Simulation","Testing" 25,"Test23.txt",,"Simulation", 26,"Test24.txt",,,"Testing" My resources are limited. You must ask the right questions
Zedna Posted October 31, 2018 Posted October 31, 2018 Here is something for you to start with ... expandcollapse popup#include <Array.au3> #include <File.au3> #include <GUIConstantsEx.au3> #include <GuiListBox.au3> ;~ Global $Files[1] ;~ Global $File_Attr[1][3] ;~ Global $DB_Name = "C:\Users\price98\Desktop\Neuer Ordner\Database4.accdb" Global $DB_Name = @ScriptDir & "\Database4.accdb" Global $Table_Name = "bhanu" ;~ Global $Attr_Name[3] = ["111", "222", "333"] ;~ _DBUpdate() $Form_Main = GUICreate("GUI managing Database", 250, 380) ;~ $Group_Attributes = GUICtrlCreateGroup("Attributes", 20, 20, 200, 130) ;~ $Checkbox_1 = GUICtrlCreateCheckbox($Attr_Name[0], 40, 50) ;~ $Checkbox_2 = GUICtrlCreateCheckbox($Attr_Name[1], 40, 80) ;~ $Checkbox_3 = GUICtrlCreateCheckbox($Attr_Name[2], 40, 110) $idAddFile = GUICtrlCreateButton("Add", 160, 110, 50, 20) $Group_Files = GUICtrlCreateGroup("Files", 20, 160, 200, 200) $List = GUICtrlCreateList("", 40, 180, 180, 180) GUISetState(@SW_SHOW) ; GUI loop While 1 $msg = GUIGetMsg() Switch $msg ;~ Case $Checkbox_1, $Checkbox_2, $Checkbox_3 ;~ GUICtrlSetData($List, "") ;~ Access($Checkbox_1) ;~ Access($Checkbox_2) ;~ Access($Checkbox_3) Case $GUI_EVENT_CLOSE ; Close GUI ExitLoop Case $idAddFile $sFiles = FileOpenDialog("Select Files", @ScriptDir, "Text Files(*.txt)", 5) If @error Then ContinueLoop $AdoCon = ObjCreate("ADODB.Connection") $AdoCon.Open("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & $DB_Name) $AdoRs = ObjCreate("ADODB.Recordset") $AdoRs.CursorType = 2 $AdoRs.LockType = 3 $AdoRs.Open("SELECT * FROM " & $Table_Name, $AdoCon) $aFiles = StringSplit($sFiles, "|") For $i = 1 To $aFiles[0] $sFile = $aFiles[$i] ; FileName $sFileContent = FileRead($sFile) $aRows = StringSplit($sFileContent, @CRLF, 1) ; ******************************************************************************** ; variant of adding only FIRST line of each file $aCols = StringSplit($aRows[1], ",", 1) ; comma as columns separator in TXT? $AdoRs.AddNew $AdoRs.Fields("Feld1").value = $sFile $AdoRs.Fields("Feld2").value = $aCols[1] $AdoRs.Fields("Feld3").value = $aCols[2] $AdoRs.Fields("Feld4").value = $aCols[3] $AdoRs.Update ; ******************************************************************************** ; variant of adding ALL lines of each file ;~ For $j = 1 To $aRows[0] ;~ $aCols = StringSplit($aRows[$j], ",", 1) ; comma as columns separator in TXT? ;~ $AdoRs.AddNew ;~ $AdoRs.Fields("Feld1").value = $sFile ;~ $AdoRs.Fields("Feld2").value = $aCols[1] ;~ $AdoRs.Fields("Feld3").value = $aCols[2] ;~ $AdoRs.Fields("Feld4").value = $aCols[3] ;~ $AdoRs.Update ;~ Next Next $AdoRs.close $AdoCon.Close ;~ _DBUpdate() GUICtrlSetData($List, "") ;~ Access($Checkbox_1) ;~ Access($Checkbox_2) ;~ Access($Checkbox_3) EndSwitch WEnd ;~ Func Access($Checkbox) ;~ If GUICtrlRead($Checkbox) = $GUI_CHECKED Then ;~ Local $Chkbox_label = GUICtrlRead($Checkbox, 1) ;~ For $i = 0 To UBound($Files) - 1 Step 1 ;~ If $File_Attr[$i][0] = $Chkbox_label Or $File_Attr[$i][1] = $Chkbox_label Or $File_Attr[$i][2] = $Chkbox_label Then ;~ _GUICtrlListBox_AddString($List, $Files[$i]) ;~ EndIF ;~ Next ;~ EndIF ;~ EndFunc ;~ Func _DBUpdate() ;~ $AdoCon = ObjCreate("ADODB.Connection") ;~ $AdoCon.Open("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & $DB_Name) ;~ $AdoRs = ObjCreate("ADODB.Recordset") ;~ $AdoRs.CursorType = 1 ;~ $AdoRs.LockType = 3 ;~ $AdoRs.Open("SELECT COUNT(*) FROM " & $Table_Name, $AdoCon) ;~ $dimension = $AdoRs.Fields(0).Value ;~ ReDim $Files[$dimension] ;~ ReDim $File_Attr[$dimension][3] ;~ For $i = 0 To UBound($Files) - 1 Step 1 ;~ $AdoRs = ObjCreate("ADODB.Recordset") ;~ $AdoRs.CursorType = 1 ;~ $AdoRs.LockType = 3 ;~ $AdoRs.Open("SELECT * FROM " & $Table_Name & " WHERE ID = " & ($i + 1), $AdoCon) ;~ $Files[$i] = $AdoRs.Fields(1).Value ;~ $File_Attr[$i][0] = $AdoRs.Fields(2).Value ;~ $File_Attr[$i][1] = $AdoRs.Fields(3).Value ;~ $File_Attr[$i][2] = $AdoRs.Fields(4).Value ;~ Next ;~ $AdoRs.Close ;~ $AdoCon.Close ;~ Local $a = 0 ;~ For $i = 0 To UBound($Files) - 1 Step 1 ;~ For $j = 0 To 2 Step 1 ;~ If $a < 3 And Not $File_Attr[$i][$j] = "" Then ;~ For $k = $a To 2 Step 1 ;~ If $Attr_Name[$k] = $File_Attr[$i][$j] Then ;~ ContinueLoop 2 ;~ EndIf ;~ Next ;~ $Attr_Name[$a] = $File_Attr[$i][$j] ;~ $a = $a + 1 ;~ EndIf ;~ Next ;~ Next ;~ EndFunc Resources UDF ResourcesEx UDF AutoIt Forum Search
mLipok Posted October 31, 2018 Posted October 31, 2018 (edited) Try to use ADO.au3 UDF In MS SQL in table, the desired column should have "image" as "Data type" In MS ACCESS the column property is called ... how you think ?? Spoiler Attachment eventually OLE Objecthttps://docs.microsoft.com/pl-pl/office/vba/access/concepts/miscellaneous/datatype-property Never used to save File as binary data in MS ACCESS DB , so I'm not sure here. File Should be read as $FO_BINARY: Local $hFile = FileOpen('FileFullPath',$FO_BINARY) Local $dBinaryData = FileRead($hFile ) FileClose($hFile) $dBinaryData should be Inseted by SQLQuery = "Insert Into " like this MS SQL Example: ..... Local $sQuery = _ "INSERT INTO [" & $s_SQL_CATALOG & "].dbo.[Documents]" & @CRLF & _ "([IDCase],[BINARY],[ext]) OUTPUT inserted.[IDDocument]" & @CRLF & _ "VALUES(" & $i_IDCase & "," & $dBinaryData & ",'" & $sExtension & "')" & @CRLF & _ "" Local $oRecordset = _ADO_Execute($oConnection, $sQuery) ..... EDIT: of course you can also save file name , but this is realted to specyfic database structure, but in my example it was not important. You can think about [ext] and $sExtension like a FileName. Edited October 31, 2018 by mLipok Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24
price98 Posted November 14, 2018 Author Posted November 14, 2018 Thanks for suggestions. I did something. But I am getting following error line(264) : ==> The requested action with this object has failed.: $AdoCon.Open("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & $pathToDB) $AdoCon^ ERROR Can anyone resolve this problem? Thanks gui1.au3 Database4.accdb
Moderators JLogan3o13 Posted November 14, 2018 Moderators Posted November 14, 2018 @price98 The error is telling you what the problem is. You try to create the ADODB connection $AdoCon and it fails, so when you try to do $AdoCon.Open, there is no object to open. Your script is severely lacking in error checking, which is going to make it more difficult to pinpoint errors as you move forward. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
mLipok Posted November 14, 2018 Posted November 14, 2018 (edited) 6 hours ago, price98 said: Thanks for suggestions. I did something. But I am getting following error line(264) : ==> The requested action with this object has failed.: $AdoCon.Open("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & $pathToDB) $AdoCon^ ERROR Can anyone resolve this problem? add COM ERROR HANDLER by adding this: ; 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 to your script and by modyfing function which contain Line #264 I mean this function: Func _DBConnect() $AdoCon = ObjCreate("ADODB.Connection") $AdoCon.Open("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & $pathToDB) return $AdoCon EndFunc In this way: Func _DBConnect() Local $oErrorHandler = ObjEvent("AutoIt.Error", _ErrFunc) ; each function using COM/ActiveX object should use COM ERROR Handler - Global or Local (like in this case). #forceref $oErrorHandler ; Error monitoring. This will trap all COM errors while alive. ; This particular object is declared as local, meaning after the function returns it will not exist. $AdoCon = ObjCreate("ADODB.Connection") $AdoCon.Open("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & $pathToDB) return SetError(@error,@extended, $AdoCon) ; returnig $AdoCon just after invoking method you should return @error and @extended by using SetError(..) EndFunc Of course you should modyfi all your functions or just use my ADO.au3 as suggest to you recently. Edited November 14, 2018 by mLipok Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24
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