我的ini文件是这样配置的
[ConnStr]
ServerPath_1        = winxpensqlmk
Pass_1              = haier_2012
UserName_1          = sa
DBName_1            = Z100ServerPath_2        = winxpensqlmk
Pass_2              = haier_2012
UserName_2          = sa
DBName_2            = Z100_2
[Common] 
UpdateCount = 100要实现打开数据库对个表格进行操作,,请问我该怎么做啊,,,,求大神指点~ T-T。。

解决方案 »

  1.   


    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 IfEnd 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
      

  2.   

    读取ServerPath_1的值调用
    Getini("ConnStr","ServerPath_1 ","","你的ini文件路径")
      

  3.   

    然后把读取到的ini的变量写到SQL连接字符串就行了