Peltier Fr
Peltier Fr

Reputation: 45

How to read a list of values in app.config and populate a combo (VB)

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

Answers (2)

Tim Schmelter
Tim Schmelter

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

Sohail Hameed
Sohail Hameed

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

Related Questions