Jump to content

Recommended Posts

Posted

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

 

Posted

Here is something for you to start with ...

#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

 

Posted (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 ??

  Reveal hidden contents

:)

 

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 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 Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • 2 weeks later...
Posted

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
Posted

@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!

Posted (edited)
  On 11/14/2018 at 9:08 AM, 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?

Expand  

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 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 Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...