Hi,
That if you select and connectionstring that the database will automatically be loaded with a specific table - in this case: TripElement. Because I have it now hard coded, like this:
private string _connectionString = @"server=DEV12;database=prod_CycleTours_net2_backup_201107110300;uid=sa;pwd=misoft;";
I have a listbox with a list of connectionstrings and if you select an connectionstring from the listbox then automatically the database with the specific column will be loaded
I triied like this:
[code]
private void btn_SelectDatabase_Click(object sender, EventArgs e)
{
using (var _connectionString = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
using (var command = connection.CreateCommand())
{
command.CommandText = "SELECT ColumnName FROM [check]";
connection.Open();
using (var reader = command.ExecuteReader())
{
while (reader.Read())
txtConfigurationName.Text = reader["TripElement"].ToString();
}
}
}
[/code]
How to load Automatically a database
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Abhineet SrivastavaRank #1,890 · 783 reputationPosted Sep 5, 2013, 6:35 PM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Sep 5, 2013, 8:29 PM EDT
I think, you want to create connection string dynamically right?
If yes than you can put setting like database name, server name etc into the config file.
one more thing connection made on database not on table.
hope this will help you.