用 Private Declare Function GetPrivateProfileString _ Lib "kernel32" Alias "GetPrivateProfileStringA" _ (ByVal lpApplicationName As String, _ ByVal lpKeyName As Any, _ ByVal lpDefault As String, _ ByVal lpReturnedString As String, _ ByVal nSize As Long, _ ByVal lpFileName As String) As Long Private Function ReadINI(SectionName As String, KeyName As String, DefaultValue As String, INIFileName) As String '此函数是读取INI文件的,但不知对C:\ 下的文件可有用 Dim TempStr As String Dim TempNum As Long Dim GetNum As Long Dim PathFileName As String Dim ReturnStr As String TempStr = String$(255, Chr$(0)) TempNum = 255 If Right(App.Path, 1) = "\" Then PathFileName = App.Path & INIFileName Else PathFileName = App.Path & "\" & INIFileName End If GetNum = GetPrivateProfileString(SectionName, KeyName, DefaultValue, TempStr, TempNum, PathFileName) If GetNum = 0 Then ReturnStr = "" Else ReturnStr = Mid(TempStr, 1, GetNum) End If ReadINI = ReturnStr End Function Dim ADOString As String Dim UserID As String Dim PassWD As String Dim DataBase As String Dim ServerName As String UserID = ReadINI("ServerDataBase", "UserId", "", "WorkTime.INI") '"sa" PassWD = ReadINI("ServerDataBase", "DatabasePassword", "", "WorkTime.INI") '"" DataBase = ReadINI("ServerDataBase", "Database", "", "WorkTime.INI") '"db_worktime" ServerName = ReadINI("ServerDataBase", "ServerName", "", "WorkTime.INI") '"bys_home" ADOString = "Provider=SQLOLEDB.1;Password=" & PassWD & ";Persist Security Info=False;User ID=" & UserID & ";Initial Catalog=" & DataBase & ";Data Source=" & ServerName con.Open ADOString配置文件中写
[ServerDataBase] DBMS=MSS Microsoft SQL Server 6.x Database=db_WorkTime UserId=sa DatabasePassword= LogPassword= ServerName=notebook LogId=sa Lock= DbParm= Prompt=0AutoCommit=1 [Config] computerid=001
打包时怎末办
安装它自动把我的数据库安到运行程序路径下?而且DataGrid控件怎末和纪录集绑定呀??自己还要些好多代码!!
Private Declare Function GetPrivateProfileString _
Lib "kernel32" Alias "GetPrivateProfileStringA" _
(ByVal lpApplicationName As String, _
ByVal lpKeyName As Any, _
ByVal lpDefault As String, _
ByVal lpReturnedString As String, _
ByVal nSize As Long, _
ByVal lpFileName As String) As Long
Private Function ReadINI(SectionName As String, KeyName As String, DefaultValue As String, INIFileName) As String
'此函数是读取INI文件的,但不知对C:\ 下的文件可有用
Dim TempStr As String
Dim TempNum As Long
Dim GetNum As Long
Dim PathFileName As String
Dim ReturnStr As String
TempStr = String$(255, Chr$(0))
TempNum = 255
If Right(App.Path, 1) = "\" Then
PathFileName = App.Path & INIFileName
Else
PathFileName = App.Path & "\" & INIFileName
End If
GetNum = GetPrivateProfileString(SectionName, KeyName, DefaultValue, TempStr, TempNum, PathFileName)
If GetNum = 0 Then
ReturnStr = ""
Else
ReturnStr = Mid(TempStr, 1, GetNum)
End If
ReadINI = ReturnStr
End Function
Dim ADOString As String
Dim UserID As String
Dim PassWD As String
Dim DataBase As String
Dim ServerName As String
UserID = ReadINI("ServerDataBase", "UserId", "", "WorkTime.INI") '"sa"
PassWD = ReadINI("ServerDataBase", "DatabasePassword", "", "WorkTime.INI") '""
DataBase = ReadINI("ServerDataBase", "Database", "", "WorkTime.INI") '"db_worktime"
ServerName = ReadINI("ServerDataBase", "ServerName", "", "WorkTime.INI") '"bys_home"
ADOString = "Provider=SQLOLEDB.1;Password=" & PassWD & ";Persist Security Info=False;User ID=" & UserID & ";Initial Catalog=" & DataBase & ";Data Source=" & ServerName
con.Open ADOString配置文件中写
DBMS=MSS Microsoft SQL Server 6.x
Database=db_WorkTime
UserId=sa
DatabasePassword=
LogPassword=
ServerName=notebook
LogId=sa
Lock=
DbParm=
Prompt=0AutoCommit=1
[Config]
computerid=001