Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing current ADO Record to another function

Tags:

vba

vb6

adodb

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?

like image 340
nunzabar Avatar asked Mar 27 '13 12:03

nunzabar


People also ask

What is ADO Recordset?

The ADO Recordset object is used to hold a set of records from a database table. A Recordset object consist of records and columns (fields). In ADO, this object is the most important and the one used most often to manipulate data from a database.

Which cursor type in ADO can move to any record in Recordset?

Dynamic cursor Allows you to view additions, changes, and deletions by other users; allows all types of movement through the Recordset that doesn't rely on bookmarks; and allows bookmarks if the provider supports them.

Which methods is used to open ADO Recordset?

The default cursor for an ADO Recordset is a forward-only, read-only cursor located on the server. Using the Open method on a Recordset object opens a cursor that represents records from a base table, the results of a query, or a previously saved Recordset.

What is Recordset C#?

Recordset.Net is a library to convert . NET POCOs to ADODB.


2 Answers

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.

like image 163
George Mastros Avatar answered Sep 23 '22 12:09

George Mastros


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

like image 21
gbrooksman Avatar answered Sep 22 '22 12:09

gbrooksman