【问题标题】:VB.NET Sample app.config AccessVB.NET 示例 app.config 访问
【发布时间】:2010-12-23 22:51:05
【问题描述】:

谁能提供一个示例代码,展示如何将 app.config 文件与用 VB.NET 编写的应用程序集成。具体来说,我需要从 app.config 文件中提取数据库连接字符串。

【问题讨论】:

    标签: vb.net app-config


    【解决方案1】:

    见:

    Public Shared Function GetConnectionString(ByVal strConnection As String) As String
       'Declare a string to hold the connection string
       Dim sReturn As New String("")
       'Check to see if they provided a connection string name
       If Not String.IsNullOrEmpty(strConnection) Then
          'Retrieve the connection string fromt he app.config
          sReturn = ConfigurationManager. & _
          ConnectionStrings(strConnection).ConnectionString
       Else
          'Since they didnt provide the name of the connection string
           'just grab the default on from app.config
          sReturn = ConfigurationManager. & _
          ConnectionStrings("YourConnectionString").ConnectionString
       End If
       'Return the connection string to the calling method
       Return sReturn
    End Function
    

    【讨论】:

      猜你喜欢
      • 2012-11-07
      • 2020-05-15
      • 2011-08-24
      • 2010-11-30
      • 2015-05-23
      • 1970-01-01
      • 2012-07-24
      • 2012-06-02
      • 1970-01-01
      相关资源
      最近更新 更多