Jump to content

Result as an array


Recommended Posts

I have been retrieving values from MSACCESS databases using the guide on this site. http://vista.tutorialref.com/autoit/autoit-access-database.html

I have modified it a bit to work with accdb's, but it still works. Currently though it only returns one result. Anyone know how to make it show the 3-4 that it should return by the query in an array?

Code:

$dbname = "p:\Pallet Tag\Pallet Tracking_be.accdb"
$query = "SELECT PalletCreate.PalletID FROM PalletCreate LEFT JOIN PalletTruck ON PalletCreate.[PalletID] = PalletTruck.[PalletID] WHERE (((PalletTruck.PalletID) Is Null))"
Local $title
$adoCon = ObjCreate("ADODB.Connection")
$adoCon.Open ("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & $dbname)
$adoRs = ObjCreate ("ADODB.Recordset")
$adoRs.CursorType = 1
$adoRs.LockType = 3
$adoRs.Open ($query, $adoCon)
$title = $adoRs.Fields("PalletID").value
MsgBox(0,"testing",$title)
EndSwitch
Link to comment
Share on other sites

Link to comment
Share on other sites

You've created a recordset, now you need need to advance the cursor through until EOF.

Try something like this after the $adoRS.Open statement:

$cnt = 0
While Not $adoRS.EOF
    $cnt += 1
    Msgbox(0,"Record " & $cnt, $adoRs.Fields("PalletID").value)
    $adoRS.MoveNext
WEnd
$adoRS.Close
Edited by Spiff59
Link to comment
Share on other sites

You've created a recordset, now you need need to advance the cursor through until EOF.

Try something like this after the $adoRS.Open statement:

$cnt = 0
While Not $adoRS.EOF
$cnt += 1
Msgbox(0,"Record " & $cnt, $adoRs.Fields("PalletID").value)
$adoRS.MoveNext
WEnd
$adoRS.Close

That worked and shows each value in the Msgbox now how would I get that into an array?

EDIT: Nevermind I got it :) Thanks for the help.

Final code:

$dbname = "p:Pallet TagPallet Tracking_be.accdb"
$query = "SELECT PalletCreate.PalletID FROM PalletCreate LEFT JOIN PalletTruck ON PalletCreate.[PalletID] = PalletTruck.[PalletID] WHERE (((PalletTruck.PalletID) Is Null))"
Local $title
$adoCon = ObjCreate("ADODB.Connection")
$adoCon.Open ("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & $dbname)
$adoRs = ObjCreate ("ADODB.Recordset")
$adoRs.CursorType = 1
$adoRs.LockType = 3
$adoRs.Open ($query, $adoCon)
$cnt = 0
Local $list[1]
While Not $adoRS.EOF
$cnt += 1
_ArrayAdd($list, $adoRs.Fields("PalletID").value)
$adoRS.MoveNext
WEnd
$adoCon.
GuiCtrlSetData($List1, _ArrayToString($list))
Edited by BryanVest
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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