Passing current ADO Record to another function

折月煮酒 提交于 2019-12-22 04:17:12

问题


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?


回答1:


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.




回答2:


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




回答3:


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



来源:https://stackoverflow.com/questions/15659047/passing-current-ado-record-to-another-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!