Visual Basic 2008 中 数据库连接模块

页面导航:首页 > 软件编程 > vb.net > Visual Basic 2008 中 数据库连接模块

Visual Basic 2008 中 数据库连接模块

来源: 作者: 时间:2016-01-18 16:54 【

Attribute VB_Name = ConnectDataBase#39;**************************************SqlServer数据库连接调用方法************************************* #39; Call SqlDataBaseConnection(192.168.1.1...
Attribute VB_Name = "ConnectDataBase"
'**************************************SqlServer连接调用方法*************************************
        '    Call SqlDataBaseConnection("192.168.1.100", "eswsy", "sa", "dyc")
       
'******************************************************************************************************
'**************************************ACCESS数据库连接调用方法*************************************
           
            'Call AccessDataBaseConnection("\\172.25.132.11\data\eswsy.mdb")
            'Call AccessDataBaseConnection(App.Path & "\eswsy.mdb")
            'Call AccessDataBaseConnection(".\eswsy.mdb")
       
'******************************************************************************************************
'定义数据库连接conn变量及记录集rs变量
'点击 "项目"-->"添加引用"-->"com选项卡"-->"microsoft  activeX data objects 2.8 library"确定
    Public Conn As New ADODB.Connection
    Public Rs As New ADODB.Recordset
    Public Sqluser As String
    Public Sqlpass As String
    Public SqlDatabase As String
    Public SqlserverIp As String
Public Sub SqlDataBaseConnection(SqlserverIp As String, SqlDatabase As String, Sqluser As String, Sqlpass As String)
    '客户端游标库提供的游标
    Conn.CursorLocation = ADODB.CursorLocationEnum.adUseClient
    Conn.Open "Provider=SQLOLEDB.1;Password=" & Sqlpass & ";Persist Security Info=True;User ID=" & Sqluser & ";Initial
Catalog=" & SqlDatabase & ";Data Source=" & SqlserverIp & ""
    '如果conn.state 返回值为0,数据库连接失败,为1连接成功
    If Conn.State = 0 Then
        MsgBox "数据库连接失败", vbOKOnly + vbInformation, "失败"
        Conn.Close
        Set Conn = Nothing
        End
    End If
End Sub
Public Sub AccessDataBaseConnection(AccessDatabase As String)
        '客户端游标库提供的游标
    Conn.CursorLocation = ADODB.CursorLocationEnum.adUseClient
    Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & AccessDatabase & ";Persist Security Info=False"
    '如果conn.state 返回值为0,数据库连接失败,为1连接成功
    If Conn.State = 0 Then
            MsgBox "数据库连接失败", vbOKOnly + vbInformation, "失败"
            Conn.Close
            Set Conn = Nothing
            End
    End If
End Sub
Tags:

文章评论

最 近 更 新
热 点 排 行
Js与CSS工具
代码转换工具

<