VB通用数据库操作方法

2018-06-18 05:18:11来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

 1.VB通用数据操作方法。

 2.通用数据库查询方法。

 3.通用数据库操作方法。

'ERP查询数据库
Public Function YZQuery(sqls As String, msgstring As String) As ADODB.Recordset
 On Error GoTo ExecuteSQL_Error
    Set cnn = New ADODB.Connection
    cnn.ConnectionString = ConnectString
    cnn.Open
    Set rst = New ADODB.Recordset
    rst.Open Trim$(sqls), cnn, adOpenKeyset, adLockOptimistic
    Set YZQuery = rst
    msgstring = "查询到 " & rst.RecordCount & " 条记录 "
ExecuteSQL_Exit:
   Set cnn = Nothing
   Exit Function
ExecuteSQL_Error:
   msgstring = "查询错误: " & err.Description
   Resume ExecuteSQL_Exit
End Function
'ERP更新数据库
Public Function YZUpdate(sqls() As String, msgstring As String) As Boolean
    Dim i As Long
 On Error GoTo ExecuteSQL_Error
    Set cnn = New ADODB.Connection
    cnn.ConnectionString = ConnectString
    cnn.Open
    cnn.BeginTrans
    For i = LBound(sqls) To UBound(sqls)
        cnn.Execute sqls(i)
    Next
    cnn.CommitTrans
    YZUpdate = True
ExecuteSQL_Exit:
   Set rst = Nothing
   Set cnn = Nothing
   Exit Function
ExecuteSQL_Error:
   msgstring = "更新错误: " & err.Description
   YZUpdate = False
   cnn.RollbackTrans
   Resume ExecuteSQL_Exit
End Function

上面查询方法与操作方法都到了ConnectString定义如下:

Public Const ConnectString = "driver={sql server};server=192.168.1.1; uid=sa; pwd=123; database=erp;"


作者:王春天 2013.11.14   地址:http://www.cnblogs.com/spring_wang/p/3423167.html

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:针对MSHFlexGrid的一系列通用方法-项目中实践代码分享

下一篇:VB高效导入Excel2003和Excel2007文件到MSHFlexGrid控件显示