一個離線ADO資料管理模組的實現

來源:互聯網
上載者:User
ado|資料 Option Explicit
Public pubcn As New ADODB.Connection
Dim temp_i As Integer
''串連資料庫
Public Sub GetConnect()
   
    On Error GoTo errorhandler:
    Dim constr As String
    If Not (pubcn.State = 0) Then
        pubcn.Close
    End If
       
    pubcn.CursorLocation = adUseClient
    pubcn.ConnectionTimeout = 5
    pubcn.Open "Provider=sqloledb;" & _
           "Network Library=DBMSSOCN;" & _'指明採用IP+連接埠方式尋找Sql Server
           "Data Source=172.17.21.125,1433;" & _
           "Initial Catalog=hpdata;" & _
           "User ID=user;" & _
           "Password=password;" & _
           "Encrypt=yes"
          
    pubcn.DefaultDatabase = "hpdata" ''!!!!!!!!!!!!!!!!
    Exit Sub
errorhandler:
    Dim msg As Integer
    msg = MsgBox("串連時發生錯誤:" & Err.Number & Err.Description & Err.Source & "請將此資訊發至郵箱", vbOKOnly)

End Sub

''簡單查詢得到資料集////////////////////////////////////////////////////////
Public Function GetRS(sqlstr As String) As ADODB.Recordset
   
    On Error GoTo errorhandler
    Call GetConnect
   
    Set GetRS = New ADODB.Recordset
   
    GetRS.Open sqlstr, pubcn, adOpenStatic, adLockOptimistic
   
    Set GetRS.ActiveConnection = Nothing
   
    pubcn.Close
    Exit Function
errorhandler:
    Dim i As Integer
    i = MsgBox(sqlstr & ":::::::" & Err.Description & Err.HelpContext, vbOKCancel)

End Function
'同步資料集
Public Sub UpdateRS(Rs As ADODB.Recordset, Optional RequerryFlag As Integer)
    Call GetConnect
   
    With Rs
        .ActiveConnection = pubcn
        .Update
        'If (Not IsMissing(RequerryFlag)) And RequerryFlag = 1 Then ''改於2004年2月6日為修除記錄本客戶號查詢的修改無法資料同步而設
           ' .Requery
        'End If
        .ActiveConnection = Nothing
    End With
       
    pubcn.Close

End Sub
'執行帶有參數對象的查詢得到資料集
Public Sub GetRSFromCmd(Cmd As ADODB.Command, str As String, Rs As ADODB.Recordset)
   
    On Error GoTo errorhandler
    Call GetConnect
    If Not (Cmd.State = adStateClosed) Then
        Cmd.Cancel
        Cmd.ActiveConnection = Nothing
    End If
    With Cmd
        .ActiveConnection = pubcn
        .CommandTimeout = 5
        .CommandType = adCmdText
        .CommandText = str
    End With
    If Not (Rs.State = 0) Then
        Rs.Close
    End If
    Rs.Open Cmd, , adOpenStatic, adLockOptimistic
  
    Rs.ActiveConnection = Nothing
   
    With Cmd
        .ActiveConnection = Nothing
    End With
    pubcn.Close
    Exit Sub
errorhandler:
    temp_i = MsgBox(str & Err.Number & Err.Description & Err.Source, vbOKOnly)
   
End Sub

       '執行無返回結果的sql語句      

Public Sub CnExecute(ByVal Qstr As String, ByRef RecordNumber As Long, Optional QRs As ADODB.Recordset)
 &n



相關文章

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。