Sign in to follow this  
Followers 0
Jewtus

ADODB.Recordset trouble

7 posts in this topic

I'm running the following code

$sqlRs = ObjCreate("ADODB.Recordset")
$sqlRs.open ($SQLQUERY,$SqlConn)
$aOptionValue = $sqlRs.Fields ($fieldname).Value

and it returns the value I'm looking for, but the problem is, there should be two different values. I was expecting an array as a result, but I'm clearly missing something. Anyone have suggestions?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

If you want to get more than one column from select then you can use this:
$aOptionValue1 = $sqlRs.Fields (0).Value
$aOptionValue2 = $sqlRs.Fields (1).Value

Edited by Zedna

Share this post


Link to post
Share on other sites

Are you expecting the query to return multiple records? It isn't possible to tell from the limited information you posted. If so, then you need to use $sqlRs..MoveNext to access the subsequent records.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I'm running the following code

$sqlRs = ObjCreate("ADODB.Recordset")
$sqlRs.open ($SQLQUERY,$SqlConn)
$aOptionValue = $sqlRs.Fields ($fieldname).Value

and it returns the value I'm looking for, but the problem is, there should be two different values. I was expecting an array as a result, but I'm clearly missing something. Anyone have suggestions?

 

If you need to get more rows then do it like this:

$sqlRs = ObjCreate("ADODB.Recordset")
$sqlRs.open ($SQLQUERY,$SqlConn)

While Not $sqlRs.EOF
    $aOptionValue = $sqlRs.Fields ($fieldname).Value
    ConsoleWrite($aOptionValue & @CRLF)
    $sqlRs.MoveNext
WEnd
Edited by Zedna
1 person likes this

Share this post


Link to post
Share on other sites

That was it. Thanks all!

Share this post


Link to post
Share on other sites

Hi all

you can use a method of recordset object to get an array from it

take a look here: http://www.w3schools.com/ado/met_rs_getrows.asp

$aReturn = $sqlRs.GetRows([$NumRows, [$Start, [$aFields]]])

for complete reading use this

    Local $aReturn = $sqlRs.GetRows()
    _ArrayDisplay($aReturn)

    $sqlRs.MoveFirst
    While Not $sqlRs.EOF
        ConsoleWrite("Row " & $sqlRs.AbsolutePosition & @LF)
        ;; Method 1
        ConsoleWrite(@TAB & "Method 1" & @LF)
        For $Field In $sqlRs.Fields
            ConsoleWrite(@TAB & $Field.Name & " = " & $Field.Value & @LF)
        Next
        ;; Method 2
        ConsoleWrite(@LF & @TAB & "Method 2" & @LF)
        For $i = 0 To $sqlRs.Fields.Count - 1
            ConsoleWrite(@TAB & $sqlRs.Fields($i).Name & " = " & $sqlRs.Fields($i).Value & @LF)
        Next
        $sqlRs.MoveNext
    WEnd

 

Share this post


Link to post
Share on other sites

BTW: A good tutorial about ADO and AutoIt can be found here.

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-02-03 - Version 1.4.7.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-03 - Version 1.2.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

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

  • Similar Content

    • Valnurat
      By Valnurat
      I hope my title is good enough.
      I'm using the ADO UDF and I have question regarding editing SQL records with this UDF.
      The owner of the UDF suggested an idea, but maybe there is another trix.
    • Paranthaman
      By Paranthaman
      Hi,
      I want to click a link by the element ID through IEGetObjById.
      <!DOCTYPE html> <html> <body> <button type="button" id="Random-1-ID" onclick="alert('Hello world!')"></button> </body> </html> I intend to click the button with ID"Random-1-ID". But on every refresh the ID changes to next number like "Random-2-ID" "Random-3-ID"
       
      The code i which i wrote for this function is
      #include <IE.au3> #include <MsgBoxConstants.au3> Local $oIE = _IECreate("I:\Documents\1. Work\Automation\My codes\Collections\11. Clicking button by Value and ID\button.html") Local $oDiv = _IEGetObjById($oIE, "Random-1-ID") _IEAction($oDiv, "click") _IELoadWait($oIE) So can anyone help me to alter this code like it clicks for every ID in format "Random-%-ID"
    • Trong
      By Trong
      DB1:
      CREATE TABLE [dbo].[Item]( [ItemID] [nchar](10) NOT NULL, [Money] [bigint] NOT NULL, CONSTRAINT [PK_Item] PRIMARY KEY CLUSTERED ( [ItemID] ASC ) ON [PRIMARY] ) ON [PRIMARY] GO CREATE TABLE [dbo].[Account]( [Index] [int] IDENTITY(1,1) NOT NULL, [AccountID] [nchar](10) NOT NULL, [AccountName] [int] NOT NULL, [ItemList] [int] NOT NULL, ) ON [PRIMARY] GO CREATE TABLE [dbo].[Money]( [AccountID] [nchar](10) NOT NULL, [Money] [bigint] NOT NULL, CONSTRAINT [PK_Money] PRIMARY KEY CLUSTERED ( [AccountID] ASC ) ON [PRIMARY] ) ON [PRIMARY] GO  
      DB2:
      CREATE TABLE [dbo].[Item]( [ItemID] [nchar](10) NOT NULL, [Money] [bigint] NOT NULL, [ItemName] [bigint] NOT NULL, [MoneyType] [bigint] NOT NULL, CONSTRAINT [Item] PRIMARY KEY CLUSTERED ( [ItemID] ASC ) ON [PRIMARY] ) ON [PRIMARY] GO CREATE TABLE [dbo].[Account]( [Index] [int] IDENTITY(1,1) NOT NULL, [AccountID] [nchar](10) NOT NULL, [AccountName] [int] NOT NULL, [ItemList] [int] NOT NULL, ) ON [PRIMARY] GO CREATE TABLE [dbo].[Money]( [AccountID] [nchar](10) NOT NULL, [Money] [bigint] NOT NULL, [MoneyType] [bigint] NOT NULL, CONSTRAINT [Money] PRIMARY KEY CLUSTERED ( [AccountID] ASC ) ON [PRIMARY] ) ON [PRIMARY] GO  
      Compare and merge database.
      alter table [Item] add [ItemName] bigint not null default(0) alter table [Item] add [MoneyType] bigint not null default(0) alter table [Money] add [MoneyType] bigint not null default(0) Please help automate code AutoIt to generation new code for large sql file.
      Thanks
    • WoodGrain
      By WoodGrain
      Hi guys,
      This post was originally going to be a question on how to fix this issue but as I ended up figuring it out I thought I'd post it here for others that have the same issue.
      So you've downloaded and extracted the latest version of the SQLite dll files etc into the same directory as your SQLite script but it's failing at _SQLite_Startup()?
      What you need to do, that I couldn't see anywhere in the documentation, to fix the issue is rename the dll files from (for example) "sqlite3_301500000.dll" to "sqlite3.dll" and "sqlite3_x64_301500000.dll" to "sqlite3_x64.dll".
      Fixed my issues instantly!
      Hope it can help others too.
      Cheers.
    • S0lidFr0st
      By S0lidFr0st
      Hello! I'm fairly new to using Autoit, I like the language and simplicity, however, there is a bit of a learning curve for me. I'm stuck and need some community help!
      I need to manipulate a query by using GUICtrlCreateDate to select the correct date and pipe the selected date into my actual query in a specific format (yyyymmdd).
      Here is an example:
      _Flag_RecordsetDisplay($sConnectionString, "select * from trips_to_complete_20161122 where trip_type in ('P','C') and trip_status in ('S','PC','DC') and Flagged = 1") Func _Flag_RecordsetDisplay($sConnectionString, $sQUERY) ; Create connection object Local $oConnection = _ADO_Connection_Create() ; Open connection with $sConnectionString _ADO_Connection_OpenConString($oConnection, $sConnectionString) If @error Then Return SetError(@error, @extended, $ADO_RET_FAILURE) ; Executing some query directly to Array of Arrays (instead to $oRecordset) Local $aRecordset = _ADO_Execute($oConnection, $sQUERY, True) ; Clean Up _ADO_Connection_Close($oConnection) $oConnection = Null ; Display Array Content with column names as headers _ADO_Recordset_Display($aRecordset, 'Recordset content') EndFunc ;==>_Flag_RecordsetDisplay The part of the query that needs modified is "trips_to_complete_20161122" I need to be able to select a date (via the gui) and that selection pipe into my query.  
       
      Thanks in Advanced!