大家好,欢迎来到IT知识分享网。
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 地址:VB通用数据库操作方法
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/32620.html