vba 将当前 ADO 记录传递给另一个函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15659047/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Passing current ADO Record to another function
提问by nunzabar
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.
也许我在 .NET 中花费了太多时间,但是我不能轻松地将 ADO RecordSet 的当前 Record 传递给另一个方法,这似乎很奇怪。
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.
我在该主题上发现的少量信息说传递整个 RecordSet 或创建一个新的 Record 并手动将每个字段复制到它。
StackOverflow, is there a better way?
StackOverflow,有没有更好的方法?
采纳答案by George Mastros
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.
就个人而言,我会将整个记录集传递给 ProcessRecord 子例程。记录集总是通过引用传递,因此传递记录集没有开销(性能或内存消耗)。只要确保您没有移动到 ProcessRecord 子例程中的下一条记录。
回答by gbrooksman
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.
您可以使用 GetRows() 方法将数据加载到数组中,然后让 ProcessRecord 仅使用该数组,但这会“断开”该方法与数据集的连接,这可能不是您想要的。
The GetRows() method takes optional arguments to specify how many rows to get, where to start and the fields to get
GetRows() 方法采用可选参数来指定要获取的行数、从哪里开始以及要获取的字段
So:
所以:
ProcessRecord(data.GetRows(1,adBookmarkCurrent))
ProcessRecord(data.GetRows(1,adBookmarkCurrent))
should do it for all fields
应该对所有领域都这样做
回答by Potter Rafed
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
不幸的是没有......你不能从记录集中提取一个记录......正如 G. Masros 所说,通过引用传递整个记录集并使用当前记录没有额外的开销,所以你也可以这样做