VB连接SQL数据库驱动部分

VB连接SQL数据库驱动部分,第1张

概述Attribute VB_Name = "Data_SQL" Public conn As ADODB.Connection Public rs As ADODB.Recordset 'Dim proc As New ADODB.Command Public addFlag As Boolean      '声明部分 Public Function OpenCn(ByVal Cip As Stri Attribute VB_name = "Data_sql" Public conn As ADODB.Connection Public rs As ADODB.Recordset 'Dim proc As New ADODB.Command Public addFlag As Boolean '声明部分 Public Function OpenCn(ByVal Cip As String,ByVal DBname As String,ByVal users As String,ByVal pw As String) As Boolean '连接模块 填写数据库等信息 Dim mag As String On Error GoTo strerrmag Set conn = New ADODB.Connection conn.ConnectionTimeout = 25 conn.ProvIDer = "sqloledb" conn.PropertIEs("data source").Value = Cip '服务器的名字 conn.PropertIEs("initial catalog").Value = DBname '库名 'conn.PropertIEs("integrated security").Value = "sspI" '登陆类型 conn.PropertIEs("user ID").Value = users 'sql库名 conn.PropertIEs("password").Value = pw '密码 'sql = "ProvIDer=sqlolEDB.1;Persist Security Info=False;User ID=sa;password=;Initial Catalog=pubs;Data Source=127.0.0.1" '如果不用这个模块也行可以,这一句便是常用的引擎。 'conn.ConnectionString = sql Data Source=.;Initial Catalog=Andon;User ID=sa conn.Open OpenCn = True If conn.State = 1 Then addFlag = True Exit Function strerrmag: mag = "Data can't connect" Call MsgBox(mag,vbOKOnly,"Error:Data connect") addFlag = False Exit Function '连接错误消息 End Function '关闭数据库,释放连接 Public Sub cloCn() On Error Resume Next If conn.State <> adStateClosed Then conn.Close Set conn = nothing End Sub Public Function openRs(ByVal strsql As String) As Boolean '连接数据库记录集 Dim mag As String Dim rpy As Boolean On Error GoTo strerrmag Set rs = New ADODB.Recordset If addFlag = False Then rpy = True With rs .ActiveConnection = conn .CursorLocation = adUseClIEnt .CursorType = adOpenKeyset .LockType = adLockOptimistic .Open strsql End With addFlag = True openRs = True 'End '将记录集给rs Exit Function strerrmag: mag = "data not connect" Call MsgBox(mag,"error:connect") openRs = False End 'Exit Function '连接错误消息 End Function Public Sub cloRs() On Error Resume Next If rs.State <> adStateClosed Then rs.Clone Set rs = nothing '释放记录集 End Sub 总结

以上是内存溢出为你收集整理的VB连接SQL数据库驱动部分全部内容,希望文章能够帮你解决VB连接SQL数据库驱动部分所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/langs/1281019.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-09
下一篇2022-06-09

发表评论

登录后才能评论

评论列表(0条)

    保存