设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

根据不同的SQL语句获取记录集

1970-1-1 08:00| 发布者: Grant| 查看: 2737| 评论: 1

根据不同的SQL语句获取记录集

Public Function GetRS(ByVal strQuery As String) As ADODB.Recordset
    Dim RS As New ADODB.Recordset
    Dim conn As New ADODB.Connection
On Error GoTo GetRS_Error
    Set conn = CurrentProject.Connection
    RS.Open Trim$(strQuery), conn, adOpenKeyset, adLockOptimistic
    Set GetRS = RS

GetRS_Exit:
    RS.Close
    Set RS = Nothing
    conn.Close
    Set conn = Nothing
    Exit Function
GetRS_Error:
    MsgBox (Err.Description)
    Resume GetRS_Exit
End Function


'用法示例:
Dim RS As New ADODB.Recordset
Dim str As String
str = "select * from 员工表"
Set RS = GetRS(str)
'对记录集的相关操作……
……

RS.Close
Set RS=Nothing


发表评论

最新评论

引用 waikey 2008-8-7 16:16
学习学习啊

查看全部评论(1)

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-3-29 18:58 , Processed in 0.126088 second(s), 16 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

返回顶部