我的ini檔案是這樣配置的
[ConnStr]
ServerPath_1 = winxpensqlmk
Pass_1 = haier_2012
UserName_1 = sa
DBName_1 = Z100
ServerPath_2 = winxpensqlmk
Pass_2 = haier_2012
UserName_2 = sa
DBName_2 = Z100_2
[Common]
UpdateCount = 100
要實作打開資料庫對個表格進行操作,,請問我該怎么做啊,,,,求大神指點~ T-T。。
uj5u.com熱心網友回復:
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
Declare Function WritePrivateProfileString _
Lib "kernel32" _
Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, _
ByVal lpKeyName As Any, _
ByVal lpString As Any, _
ByVal lpFileName As String) As Long
'Read iniFile
Public Function Getini(nApp As String, nKey As String, nDefault As String, nFilePath As String) As String
Dim nStr As String, nSize As Long, s As Long
nSize = 1024
nStr = String(nSize, 0)
s = GetPrivateProfileString(nApp, nKey, nDefault, nStr, nSize, nFilePath) 'GetSet = Left(nStr, S)
s = InStr(nStr, vbNullChar & vbNullChar)
If s > 0 Then
Getini = Left(nStr, s - 1)
End If
End Function
'Write iniFile
Sub Writeini(nApp As String, nKey As String, nValue As String, nFilePath As String)
Dim iLen As Integer
iLen = WritePrivateProfileString(nApp, nKey, nValue, nFilePath)
End Sub
uj5u.com熱心網友回復:
讀取ServerPath_1的值呼叫Getini("ConnStr","ServerPath_1 ","","你的ini檔案路徑")
uj5u.com熱心網友回復:
然后把讀取到的ini的變數寫到SQL連接字串就行了轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/109518.html
標籤:API
