BryanVest Posted July 2, 2012 Posted July 2, 2012 I have been retrieving values from MSACCESS databases using the guide on this site. http://vista.tutorialref.com/autoit/autoit-access-database.htmlI 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
spudw2k Posted July 2, 2012 Posted July 2, 2012 Check out the _GetRecords function in the example Might give you some ideas on how to accomplish the desired result. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
Spiff59 Posted July 2, 2012 Posted July 2, 2012 (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 July 2, 2012 by Spiff59
BryanVest Posted July 2, 2012 Author Posted July 2, 2012 (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 July 2, 2012 by BryanVest
spudw2k Posted July 2, 2012 Posted July 2, 2012 Ahem... Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
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