荔园在线
荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀
[回到开始]
[上一篇][下一篇]
发信人: Jobs (温少), 信区: Visual
标 题: Quick Function for Copying ADO Recordsets
发信站: BBS 荔园晨风站 (Tue Dec 14 20:22:31 1999), 站内信件
Quick Function for Copying ADO Recordsets
As developers, many times while using ADO Recordset we copy
the Recordset to a temp Recordset to do our checks,
validations, etc. If the Recordset is read-only and if we have
to delete rows, we are left with no choice but to copy the
Recordset. Copying a Recordset can be painful, especially when
we have too many fields. So let the Function below handle it.
The Function expects two parameters—the source Recordset
that you wish to copy, and LockType, which defaults to
adLockBatchOptimistic—and then returns the copied Recordset.
Public Function CloneRecordSet(ByVal objRecordset As _
Recordset, Optional ByVal LockType As LockTypeEnum = _
adLockBatchOptimistic) As Recordset
Dim objNewRS As Recordset
Dim objField As Object
Dim lngCnt As Long
Set objNewRS = New Recordset
objNewRS.CursorLocation = adUseClient
objNewRS.LockType = LockType
For Each objField In objRecordset.Fields
objNewRS.Fields.Append objField.Name, _
objField.Type, objField.DefinedSize, _
objField.Attributes
Next objField
If Not objRecordset.RecordCount = 0 Then
objRecordset.MoveFirst
While Not objRecordset.EOF
objNewRS.AddNew
For lngCnt = 0 To objRecordset.Fields.Count - 1
objNewRS.Fields(lngCnt).Value = _
objRecordset.Fields(lngCnt).Value
Next lngCnt
objRecordset.MoveNext
Wend
End If
Set CloneRecordSet = objNewRS
End Function
--
☆ 来源:.BBS 荔园晨风站 bbs.szu.edu.cn.[FROM: bbs@192.168.11.111]
[回到开始]
[上一篇][下一篇]
荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店