vb.net如何从ini文件读取SQL的连接字符串
如题,哪位大神指点一下,我想从一个ini文件里读取服务器的地址,sa用户名,密码,和连接数据库,而且可以通过自制的FROM进行修改和保存,麻烦哪位大神给个代码学习一下
程序代码:
'聲明INI读写API函數 Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" _ (ByVal lpApplicationName As String, _ ByVal lpKeyName As String, _ ByVal lpDefault As String, _ ByVal lpReturnedString As String, _ ByVal nSize As Int32, _ ByVal lpFileName As String) As Int32 Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" _ (ByVal lpApplicationName As String, _ ByVal lpKeyName As String, _ ByVal lpString As String, _ ByVal lpFileName As String) As Int32 ' 用法: '读取INI Public Function GetINI( _ ByVal Section As String, _ ByVal AppName As String, _ ByVal lpDefault As String, _ ByVal FileName As String) As String Dim Str As String = "" Str = LSet(Str, 256) GetPrivateProfileString(Section, AppName, lpDefault, Str, Len(Str), FileName) Return Microsoft.VisualBasic.Left(Str, InStr(Str, Chr(0)) - 1) End Function '写入INI Public Function WriteINI( _ ByVal section As String, _ ByVal appName As String, _ ByVal lpDefault As String, _ ByVal fileName As String) As Long WriteINI = WritePrivateProfileString(section, appName, lpDefault, fileName) End Function