Reputation: 2437
Perhaps I've spent too much time in .NET, but it seems odd that I cannot easily pass the current Record of an ADO RecordSet to another method.
Private Sub ProcessData(data As ADODB.Recordset)
While (Not data.EOF)
ProcessRecord ([data.CurrentRecord]) ' <-- There is no CurrentRecord property.
data.MoveNext
Wend
End Sub
Private Sub ProcessRecord(singleRecord As ADODB.Record)
' Do stuff.
End Sub
The scant info I've found on the subject says to pass the entire RecordSet or to create a new Record and manually copy each field to it.
StackOverflow, is there a better way?
Upvotes: 9
Views: 10403
Reputation: 115
you can use the GetRows() method to load the data into an array and then let ProcessRecord work only with the array, but that 'disconnects' the method from the dataset and this may not be what you intend.
The GetRows() method takes optional arguments to specify how many rows to get, where to start and the fields to get
So:
ProcessRecord(data.GetRows(1,adBookmarkCurrent))
should do it for all fields
Upvotes: 2
Reputation: 481
Unfortunately no.. you cant extract a single Record from a Recordset.. as G. Mastros said there is no additional overhead passing the whole recordset by reference and work with the current record so you might as well do it like that
Upvotes: 0
Reputation: 24498
Personally, I would pass the entire recordset in to the ProcessRecord subroutine. Recordsets are always passed by reference so there is no overhead (performance or memory consumption) passing a recordset around. Just make sure you don't move to the next record in the ProcessRecord subroutine.
Upvotes: 4