Jump to content

Search the Community

Showing results for tags 'getrows'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 1 result

  1. In the code below i can write the excel sheet with an array from an ADODB GetRows command But not using _Excel_RangeWrite function Thanks for your comments, #include <Array.au3> #include <Excel.au3> ;Help: COM Error Handling Global $errADODB = ObjEvent("AutoIt.Error","_ErrADODB") Local $sFilePath = @ScriptDir & "\db.mdb" Local Const $iCursorType = 0 ; adOpenForwardOnly, 3 adOpenStatic Local Const $iLockType = 3 ;1 adLockReadOnly, 3 adLockOptimistic Local Const $iOptions = 1 ; Options, 1 Evaluates as a textual definition of a command or stored procedure call ; 2 adCmdTable Global $cn = ObjCreate("ADODB.Connection") ; Create a connection object Global $rst = ObjCreate("ADODB.Recordset") ; Create a recordset object ;Global $sADOConnectionString = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & $sFilePath ;Global $sADOConnectionString = 'DRIVER={Microsoft Access Driver (*.mdb)};Dbq=' & $sFilePath & ';uid=;pwd=MyPassword;' Global $sADOConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & $sFilePath & ";Jet OLEDB:Database Password=123" $cn.CursorLocation = 3 ; adUseClient ;https://stackoverflow.com/questions/31941487/open-adodb-connection-to-excel-file-in-read-only-mode ;https://www.w3schools.com/asp/prop_rec_mode.asp $cn.Mode = 1 ;Read-only ;$cn.CommandTimeout = 0 $cn.Open($sADOConnectionString) ; Open the connection Local $sSQL = "SELECT * FROM TABLE1" $rst.Open($sSQL, $cn, $iCursorType, $iLockType, $iOptions) ; Issue the SQL query If Not $rst.EOF = True Then Local $rstArray = $rst.GetRows() _ArrayDisplay ($rstArray) $rst.Close ;Create application object Local $oAppl = _Excel_Open() If @error Then Exit MsgBox(0, "Excel UDF: _Excel_BookOpen Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ; Create a new workbook with only 1 worksheet Local $oWorkbook = _Excel_BookNew($oAppl, 1) If @error Then Exit MsgBox(0, "Excel UDF: _Excel_BookNew Example 1", "Error creating new workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ;MsgBox(0, "Excel UDF: _Excel_BookNew Example 1", "Workbook has been created successfully with only 1 worksheets.") Local $sSheet = $oWorkbook.ActiveSheet Local $aArray1D[3] = ["Field1", "Field2", "Field3"] $sSheet.Range("A1:C1").Font.Bold = True $sSheet.Range("A1:C1").value = $aArray1D Local $RecCount = UBound($rstArray) Local $TrstArray = $rstArray _ArrayTranspose($TrstArray) ;$sSheet.Range("A2:C" & $RecCount + 1).value = $TrstArray ;<<<<<<<<<<<<<< This writes the data OK ;This fails _Excel_RangeWrite($oWorkbook, Default, $TrstArray, "A2:C" & $RecCount + 1) If @error Then MsgBox(0, "Excel UDF: _Excel_RangeWrite Example 3", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $rst = 0 ;Release the recordset object $cn.Close ;Close the connection $cn = 0 ;Release the connection object Else $rst.Close $rst = 0 ; Release the recordset object $cn.Close ; Close the connection $cn = 0 ; Release the connection object MsgBox(262144, "", "Empty" & @CRLF & "Empty recordset" , 5) EndIf Func _ErrADODB() Msgbox(0,"ADODB COM Error","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $errADODB.description & @CRLF & _ "err.windescription:" & @TAB & $errADODB.windescription & @CRLF & _ "err.number is: " & @TAB & hex($errADODB.number,8) & @CRLF & _ "err.lastdllerror is: " & @TAB & $errADODB.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $errADODB.scriptline & @CRLF & _ "err.source is: " & @TAB & $errADODB.source & @CRLF & _ "err.helpfile is: " & @TAB & $errADODB.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $errADODB.helpcontext, 5) Local $err = $errADODB.number If $err = 0 Then $err = -1 $rst = 0 $cmd = 0 $cn.Close $cn = 0 Exit EndFunc
×
×
  • Create New...