将当前的ADO记录传递给另一个函数

问题描述:

也许我在.NET中花了太多时间,但是奇怪的是我无法轻松地将ADO RecordSet的当前Record传递给另一个方法。

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

我在这个问题上发现的不足信息说可以通过整个RecordSet或创建一个新Record并手动将每个字段复制到其中。

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,还有更好的方法吗?

StackOverflow, is there a better way?

我个人将整个记录集传递给ProcessRecord子例程。记录集始终通过引用传递,因此不存在传递记录集的开销(性能或内存消耗)。只要确保您不移至ProcessRecord子例程中的下一条记录即可。

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.