Office中國(guó)論壇/Access中國(guó)論壇

 找回密碼
 注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

根據(jù)不同的SQL語(yǔ)句獲取記錄集

1970-1-1 08:00| 發(fā)布者: Grant| 查看: 2843| 評(píng)論: 1

根據(jù)不同的SQL語(yǔ)句獲取記錄集

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)
'對(duì)記錄集的相關(guān)操作……
……

RS.Close
Set RS=Nothing


發(fā)表評(píng)論

最新評(píng)論

引用 waikey 2008-8-7 16:16
學(xué)習(xí)學(xué)習(xí)啊

查看全部評(píng)論(1)

QQ|站長(zhǎng)郵箱|小黑屋|手機(jī)版|Office中國(guó)/Access中國(guó) ( 粵ICP備10043721號(hào)-1 )  

GMT+8, 2025-7-13 07:59 , Processed in 0.059875 second(s), 16 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

返回頂部