浏览器大全:是一个提供流行浏览器教程、在线学习分享的学习平台!

一个离线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)
    'On Error GoTo errorhandler
   
    Call GetConnect
    pubcn.Execute Qstr, RecordNumber, adExecuteNoRecords
   
    If IsMissing(QRs) Then
    QRs.ActiveConnection = pubcn
    QRs.Requery
    QRs.ActiveConnection = Nothing
    End If
    pubcn.Close
errorhandler:
   temp_i = MsgBox(Qstr & Err.Number & Err.Description, vbOKOnly)

End Sub





相关软件

2345加速浏览器官方版

2345加速浏览器官方版 | 56.2MB

2345加速浏览器官方版

新一代2345加速浏览器采用Chromium和IE双内核,主打极速与安全特性。基于Chromium深度定制,引入网页智能预加载技术,访问网页更快速..

QQ浏览器官方正式版

QQ浏览器官方正式版 | 49.67MB

QQ浏览器官方正式版

QQ浏览器秉承TT浏览器1-4系列方便易用的特点,但技术架构不同,交互和视觉表现也重新设计,采用Chromium内核+IE双内核,让浏览快速稳定...

百度浏览器最新版下载

百度浏览器最新版下载 | 13.3MB

百度浏览器最新版下载

q百度浏览器,是一款简洁轻快、智能懂你的浏览器。依靠百度强大的搜索平台,在满足用户浏览网页的基础上,它整合百度体系业务优势,带给用户更方便的浏览方式功能...

UC浏览器官方正式版

UC浏览器官方正式版 | 44.2MB

UC浏览器官方正式版

UC浏览器(UC Browser)是UC Mobile Limited在2004年8月开发的一款软件,分uc手机浏览器和uc浏览器电脑版。UC浏览器是全球使用量最大的第三方手机浏览器...

猎豹浏览器2022最新版下载

猎豹浏览器2022下载 | 45MB

猎豹浏览器2022最新版下载

猎豹安全浏览器对Chrome的Webkit内核进行了超过100项的技术优化,访问网页速度更快。其具有首创的智能切换引擎,动态选择内核匹配不同网页...

360安全浏览器官方版下载

360安全浏览器下载 | 21.4MB

360安全浏览器官方版下载

360安全浏览器拥有全国最大的恶意网址库,采用恶意网址拦截技术,可自动拦截挂马、欺诈、网银仿冒等恶意网址。独创沙箱技术,在隔离模式即使访问****也不会感染...