您的位置:首页 > 编程语言 > VB

VB中Recordset的clone方法

2020-02-16 05:43 363 查看
在用vb的时候,发现了个奇怪的问题,见下面代码,在生成Recordset的过程中,调用了recordset的clone方法,clone后沒有做任何操作,及時跟踪的过程中发现clone前的原recordset對象rectemp的recordcount是26,但是但调用Recordset的clone方法后,居然发现clone后新的複製本rectempcopy 比rectemp多了一倍的记录。郁闷,难道clone了还多出一倍?查询msdn,上面这么描述,

Use the Clone method to create multiple, duplicate Recordset objects, particularly if you want to be able to maintain more than one current record in a given set of records. Using the Clone method is more efficient than creating and opening a new Recordset object with the same definition as the original.
The current record of a newly created clone is set to the first record.
我也不知道是怎么回事情?郁闷。查閲了一下msdn:
Changes you make to one Recordset object are visible in all of its clones regardless of cursor type. However, once you execute Requery on the original Recordset, the clones will no longer be synchronized to the original.

Closing the original Recordset does not close its copies; nor does closing a copy close the original or any of the other copies.

You can only clone a Recordset object that supports bookmarks. Bookmark values are interchangeable; that is, a bookmark reference from one Recordset object refers to the same record in any of its clones.

再次查閲了clone原理之後,引用了博客園天伤之梦的一段話描述clone:获取浅表副本就是把这本书直接接给读者,获取深层副本就是把这本书留着(或者销毁),抄写一份给读者()。

C#中dataset的copy方法是深copy,clone方法只是淺clone而已
代码:
Dim objPrv As Object 'SYSRRVB.clsPPrv
Dim objRectemp As New ADODB.Recordset
Dim objRectempcopy, Rectempcopy1 As New ADODB.Recordset
Dim strtemp
Set objPrv = CreateObject("'SYSRRVB.clsPPrv")
If Me.chkDep.Value = 1 Then
    Set objRectemp = m_Buffer.Records(CLng(Mid(Trim$(Me.trvOrg.SelectedItem.Key), 2, 1)))
    Set objRectempcopy= objRectemp .Clone
    Set Rectempcopy1 = objRectemp
******
end if
clone的方法原理倒查閲了不少,但一直不知道爲什麽clone對象double原來的一倍?,而且增加的和原來的對象還不完全相同。?

转载于:https://www.cnblogs.com/PeterWang/archive/2004/11/04/60596.html

  • 点赞
  • 收藏
  • 分享
  • 文章举报
bahua2018 发布了0 篇原创文章 · 获赞 0 · 访问量 308 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: