Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VB.NET示例app.config访问_Vb.net_App Config - Fatal编程技术网

VB.NET示例app.config访问

VB.NET示例app.config访问,vb.net,app-config,Vb.net,App Config,任何人都可以提供一个示例代码,演示如何将app.config文件与用VB.NET编写的应用程序集成。具体而言,我需要从app.config文件中提取数据库连接字符串。请参阅: Public Shared Function GetConnectionString(ByVal strConnection As String) As String 'Declare a string to hold the connection string Dim sReturn As New Strin

任何人都可以提供一个示例代码,演示如何将app.config文件与用VB.NET编写的应用程序集成。具体而言,我需要从app.config文件中提取数据库连接字符串。

请参阅:

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