我想通过VB.net遍历App.Config中的所有连接字符串。
我希望能够完成以下两个步骤: 1. 获取所有连接字符串的数量 2. 将它们全部放入一个列表框中。
我已经尝试使用System.Configuration.ConfigurationSettings,但不确定如何准确地获取连接字符串的集合/列表。
该应用程序是一个WinForms VB.net .net 4.0应用程序。
我想通过VB.net遍历App.Config中的所有连接字符串。
我希望能够完成以下两个步骤: 1. 获取所有连接字符串的数量 2. 将它们全部放入一个列表框中。
我已经尝试使用System.Configuration.ConfigurationSettings,但不确定如何准确地获取连接字符串的集合/列表。
该应用程序是一个WinForms VB.net .net 4.0应用程序。
这应该可以工作:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' You need to add a reference to System.Configuration
' Uncomment to get the count:
' Dim count As Int32
' count = Configuration.ConfigurationManager.ConnectionStrings.Count
Dim current As Configuration.ConnectionStringSettings
For Each current In Configuration.ConfigurationManager.ConnectionStrings
ListBox1.Items.Add(current.Name)
Next
End Sub