文件名称:VB通过配置文件System.ini连接数据库
文件大小:3KB
文件格式:RAR
更新时间:2015-03-30 10:44:39
System.ini 数据库链接
Public conn As New ADODB.Connection Public nowconnectstring As String Public operatetype As Integer Public Declare Function GetPrivateProfileString Lib "Kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, lpKeyName As Any, ByVal lpDefault As String, ByVal lpRetunedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long Public Declare Function WritePrivateProfileString Lib "Kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, lpKeyName As Any, ByVal lpAdd As String, ByVal lpFileName As String) As Boolean 'Public pzhm As Variant Public server As String Public loginname As String Public database As String Public pass As String Public path As String Private mSystemData As Object '帐套连接信息对象(帐套名,当前用户等) '=================================================================='定义公用变量 '在工程中新建一模块,并将以下代码加入到该的模块中(即module1.bas) Public tmpDataGrid As DataGrid '用与确定要实现滚动的DataGrid控件 Public tmpDataGridRowNum As Long '有多少行数据 Public Const GWL_WNDPROC = (-4) Public Const WM_COMMAND = &H111; Public Const WM_MBUTTONDOWN = &H207; Public Const WM_MBUTTONUP = &H208; Public Const WM_MOUSEWHEEL = &H20A; Public Oldwinproc As Long Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long Public Property Get SystemProfile() As Object If mSystemProfile Is Nothing Then Set mSystemProfile = GLData.SystemProfile End If Set SystemProfile = mSystemProfile End Property Public Property Set SystemProfile(ByVal NewVal As Object) Set mSystemProfile = NewVal Set GLData.SystemProfile = NewVal End Property Public Property Get SystemData() As Object If mSystemData Is Nothing Then Set mSystemData = CreateObject("EBCBase.ClientBase").SystemData End If Set SystemData = mSystemData End Property '====================================== '数据库链接 Public Function connectstring() As String If Len(GetFromINI("数据库信息", "数据库", App.path + "\system.ini")) = 0 Then MsgBox "没有连接数据库", vbOKOnly, "警告" Else connectstring = GetFromINI("数据库信息", "数据库", App.path + "\system.ini") server = GetFromINI("数据库信息", "server", App.path + "\system.ini") loginname = GetFromINI("数据库信息", "loginname", App.path + "\system.ini") database = GetFromINI("数据库信息", "database", App.path + "\system.ini") pass = GetFromINI("数据库信息", "pass", App.path + "\system.ini ") path = GetFromINI("数据库信息", "path", App.path + "\system.ini ") End If End Function Public Function GetFromINI(AppName As String, KeyName As String, filename As String) As String Dim RetStr As String RetStr = String(255, Chr(0)) GetFromINI = Left(RetStr, GetPrivateProfileString(AppName, ByVal KeyName, "", RetStr, Len(RetStr), filename)) End Function Public Sub data_open() nowconnectstring = connectstring If conn.state <> 1 Then conn.CursorLocation = adUseClient conn.Open nowconnectstring End If End Sub 调用data_open方法
【文件预览】:
新建文件夹
----MSSCCPRJ.SCC(190B)
----Module1.bas(3KB)
----Form1.frm(934B)
----工程1.vbp(942B)
system.ini