| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
共有 1071 人关注过本帖
标题:vb.net如何从ini文件读取SQL的连接字符串
只看楼主 加入收藏
wenoxy
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2018-12-20
  问题点数:0  回复次数:3   
vb.net如何从ini文件读取SQL的连接字符串
如题,哪位大神指点一下,我想从一个ini文件里读取服务器的地址,sa用户名,密码,和连接数据库,而且可以通过自制的FROM进行修改和保存,麻烦哪位大神给个代码学习一下
搜索更多相关主题的帖子: vb.net ini 文件 读取 字符串 
2018-12-20 15:45
厨师王德榜
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:84
帖 子:534
专家分:2039
注 册:2013-2-16
  得分:0 
我来抛个砖吧。
程序代码:
'聲明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
2019-01-08 16:05
moou
Rank: 2
等 级:论坛游民
威 望:1
帖 子:21
专家分:40
注 册:2018-8-15
  得分:0 
我来写个实例,仅当参考
程序代码:
    '用法示例
    'config.ini文件内容
    '[服务器]
    'IP=192.168.0.250
    '[映射盘符]
    '盘符=Y:

        '判断读是否读取到取配置文件信息,并读取IP信息
        If GetINI("服务器", "IP", "", Application.StartupPath & "\config.ini") = "" Or _
           GetINI("映射盘符", "盘符", "", Application.StartupPath & "\config.ini") = "" Then
            MsgBox("配置文件错误,请进去设置界面进行设置!!!", , "国智网络")
        Else
            ReadIP = GetINI("服务器", "IP", "", Application.StartupPath & "\config.ini") 
        End If

        '写入IP到配置文件
        Dim write1 As Long
        write1 = WriteINI("服务器", "IP", "192.168.0.251", Application.StartupPath & "\config.ini")
2019-02-13 14:40
wenoxy
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2018-12-20
  得分:0 
一楼看明白,二楼的没看明白
2019-08-18 20:47
快速回复:vb.net如何从ini文件读取SQL的连接字符串
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.085082 second(s), 9 queries.
Copyright©2004-2019, BCCN.NET, All Rights Reserved