Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fill array from recordset

Status
Not open for further replies.

sal21

Programmer
Apr 26, 2004
411
0
16
IT
my query:

Set RS = New ADODB.Recordset
SQL = "SELECT COD, PREZZO, CONT FROM " & NOME_DBF_LISTINI & " WHERE COD='" & CODART & "'"
RS.Open SQL, CON, adOpenForwardOnly, adLockReadOnly

pseudo code...

I need to fill myarray with result of the query

and for the next use i need to filetr the array items based COD="1234"

then loop the result of filter
 
I need to fill myarray with result of the query"
Here is some info about it

"filetr the array items based COD="1234""
You are already doing it in: [tt]... WHERE [highlight #FCE94F]COD[/highlight]='" & CODART & "'"[/tt]

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Given that you repeatedly ask for code to put the results of a query into an array - and then want to treat that array like a recordset (filtering, searching etc) - why not just work with a disconnected recordset instead of an array, as I have previously suggested?
 
Here's an example that uses the Northwind database that ships with VB6. it illustrates the CONCEPT, but is NOT a direct solution for your post here (although it does meet the requirement to stick the recordset into an array ...).

Code:
[COLOR=blue]Option Explicit

Private Sub Command1_Click()
    Dim Cnn As ADODB.Connection
    Dim RS As Recordset
    Dim SQL As String
    Dim rsarray
    
    Set RS = New ADODB.Recordset
    Set Cnn = New ADODB.Connection
    
    With Cnn
        .Provider = "Microsoft.Jet.OLEDB.4.0" [COLOR=green]' Connecting to an MS Access 2003 (& earlier?) database[/color]
        .ConnectionString = "Data Source=C:\Program Files\Microsoft Visual Studio\VB98\NWIND.MDB;"
        [COLOR=green]'.Provider = "Microsoft.ACE.OLEDB.12.0"  'Connecting to an MS ACCESS 2007-2013 database[/color]
        .CursorLocation = [b]adUseClient[/b]
        .Open
    End With

    RS.ActiveConnection = Cnn

    SQL = "select * from customers" 
    RS.Open SQL
    
    RS.ActiveConnection = Nothing [COLOR=green][b]' Disconnect recordset[/b][/color]
    
    [COLOR=green]' Populate an array from disconnected recordset only when we need it[/color]
    RS.MoveFirst
    rsarray = RS.GetRows() [COLOR=green]' getting all rows into array. Moves rs to EOF[/color]
  
    Debug.Print UBound(rsarray, 2) + 1 [COLOR=green]' how many records retrieved into array[/color]
    Debug.Print RS.Fields(0).Name, rsarray(0, 0)
    Debug.Print RS.Fields(1).Name, rsarray(0, 1)

    RS.Filter = "CustomerID='CHOPS'" [COLOR=green]' Apply a filter
    ' Populate array with filtered data[/color]
    RS.MoveFirst
    rsarray = RS.GetRows()
 
    Debug.Print UBound(rsarray, 2) + 1 [COLOR=green]'records retrieved into array, should differ from previous count to show filter is applied[/color]
    Debug.Print RS.Fields(0).Name, rsarray(0, 0)
    

End Sub[/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top