⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clsdbconfig.cls

📁 三层代码(带备注版) 三层代码(带备注版) 三层代码(带备注版) 三层代码(带备注版) 三层代码(带备注版)
💻 CLS
字号:
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsDBConfig"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'数据库配置,包括ConnectionString的几个属性 和 一个函数(返回了连接数据库所需要的字符串)


Public Enum DBTypeEnum          '数据库类型     枚举类型        ACCESS or SQL
    access = 0
    SqlServer = 1
End Enum
Public Enum LoginTypeEnum       '登陆身份       枚举类型        WINNT or SQL
    WinNT = 0
    Sql = 1
End Enum
'注意:声明属性变量都是私有的
Private strDBName As String                     '数据库名称
Private enumDBType As DBTypeEnum                '数据库类型
Private strHostName As String                   '服务器名称
Private strLoginName As String                  '登陆名
Private strLoginPwd As String                   '登陆密码
Private enumLoginType As LoginTypeEnum          '登陆身份

Public Property Get DBName() As String
    DBName = strDBName
End Property

Public Property Let DBName(ByVal vNewValue As String)
    strDBName = vNewValue
End Property

Public Property Get DBType() As DBTypeEnum
    DBType = enumDBType
End Property

Public Property Let DBType(ByVal vNewValue As DBTypeEnum)
    enumDBType = vNewValue
End Property

Public Function GetConfigByFile()

End Function

Public Property Get HostName() As String
    HostName = strHostName
End Property

Public Property Let HostName(ByVal vNewValue As String)
    strHostName = vNewValue
End Property

Public Property Get LoginName() As String
    LoginName = strLoginName
End Property

Public Property Let LoginName(ByVal vNewValue As String)
    strLoginName = vNewValue
End Property

Public Property Get LoginPwd() As String
    LoginPwd = strLoginPwd
End Property

Public Property Let LoginPwd(ByVal vNewValue As String)
    strLoginPwd = vNewValue
End Property

Public Property Get LoginType() As LoginTypeEnum
    LoginType = enumLoginType
End Property

Public Property Let LoginType(ByVal vNewValue As LoginTypeEnum)
    enumLoginType = vNewValue
End Property
'注意:函数为public  此函数返回连接数据库的connectionstring属性,在连接数据库的函数(ConToDB)中被调用
Public Function GetConnectionString(ByVal Pdbc As clsDBConfig) '参数Pdbc:数据库的配置参数对象(这个参数是clsDBConfig类型的,包括所有配置的属性)
    Dim strCon As String
    If Pdbc.DBType = access Then            '数据库类型是ACCESS
         strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Pdbc.DBName & ";Persist Security Info=False"   'DBName为什么没有路径
    Else                                    '数据库类型是SQL
        If Pdbc.LoginType = WinNT Then      'WINNT身份登陆  不要密码
            strCon = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=" & Pdbc.DBName & ";Data Source=" & Pdbc.HostName
        Else                                'SQLserver身份登陆  需要登陆名和密码
            strCon = "Provider=SQLOLEDB.1;Password=" & Pdbc.LoginPwd & ";Persist Security Info=True;User ID=" & Pdbc.LoginName & ";Initial Catalog=" & Pdbc.DBName & ";Data Source=" & Pdbc.HostName
        End If
    End If
    GetConnectionString = strCon    '函数返回值
End Function

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -