Sign in to follow this  
Followers 0
BryanVest

Result as an array

5 posts in this topic

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

Share this post


Link to post
Share on other sites



Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Share this post


Link to post
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
Sign in to follow this  
Followers 0