Reputation: 45
I have 5 different connectionStrings in my app.config file and would like to populate a combo with these values. How can I acheve this in VB ?
Upvotes: 1
Views: 1360
Reputation: 460238
Add a reference to the System.Configuration dll
. Then you can get all connection-strings with the System.Configuration.ConfigurationManager
class:
Dim allConnections = System.Configuration.ConfigurationManager.ConnectionStrings
For Each connection As ConnectionStringSettings In allConnections
Dim connectionName = connection.Name
Dim connectionString = allConnections(connection.Name).ConnectionString
ddlConnections.Items.Add(connectionName)
Next
I assume that you don't want to show the full connection string but only it's name.
Upvotes: 1
Reputation: 988
use loop and get the all connection string like this
loop Start
//add your desired code
Web.Configuration.WebConfigurationManager.ConnectionStrings.Item(i)
loop end
Upvotes: 0