开发者

VB.NET Sample app.config Access

Could anybody supply a sample code, showing how to开发者_StackOverflow integrate the app.config file with an application written in VB.NET. Specifically I need to extract database connect strings from the app.config file.


See:

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜