Write the code as following it will display the database name but also hold the connection string of database in as value member.
comboBox1.ValueMember=ConnectionString;
comboBox1.DiaplayMember=NameOfDataBase;
abelLazm
Postaholic
2,113 posts since Feb 2011
Reputation Points: 219
Solved Threads: 124
You, can not do like Concatenating to the app.config, but instead you can use the help of two more text boxes for storing the Username and Password and also two radio buttons for seeing whether it is Sql server authentication or Windows authentication.
Saikalyankumar
Junior Poster in Training
91 posts since Mar 2011
Reputation Points: 8
Solved Threads: 23
You can use a Dictionary collection object:
public partial class Form1 : Form
{
Dictionary<string, string> connStrings;
public Form1()
{
InitializeComponent();
connStrings = new Dictionary<string, string>();
connStrings.Add("Connection string 1", "Your full connection string 1");
connStrings.Add("Connection string 2", "Your full connection string 2");
connStrings.Add("Connection string 3", "Your full connection string 3");
//the name in comboBox will be a value of dictionary
//the key of the dictionary will be the full connection string:
comboBox1.DataSource = new BindingSource(connStrings, null);
comboBox1.DisplayMember = "Value";
comboBox1.ValueMember = "Key";
comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged);
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string connString = ((KeyValuePair<string, string>)comboBox1.SelectedItem).Value;
MessageBox.Show("This is your connection string:\n" + connString);
}
}
Mitja Bonca
Nearly a Posting Maven
2,485 posts since May 2009
Reputation Points: 641
Solved Threads: 474