Problem with connection variable to Bank C # Visual Studio

1

I have my connection string that takes the connection variable from the App.Config

static String string_conn = ConfigurationManager.ConnectionStrings["bd1"].ConnectionString;

But I put a function that lists the banks in a Combobox in the login form and sends the name of the connection to that main form that contains the above connection, but I need this value that comes from the form login to be in place of that

  

ConnectionStrings ** ["bd1"] **

For example:

   String nomeConexao = Form1.LoginInfo.StringConexao;

static String string_conn = ConfigurationManager.ConnectionStrings[nomeConexao ].ConnectionString;

In other words, instead of

ConnectionStrings["bd1"]

Stay

ConnectionStrings[nomeConexao ]

I'm not sure what to do,     

asked by anonymous 31.05.2018 / 20:15

2 answers

0

I was able to solve it! I was putting the code snippet in the wrong place, it was my oversight.

I was putting out the button's click function.

    
01.06.2018 / 03:35
1

My suggestion would be to do the following.

Declare your connection variable like this:

string _conn;

And in the event of% change of% of your index , put the following code:

private void ComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    var selectedConn = (sender as ComboBox).Text;

    _conn = ConfigurationManager.ConnectionStrings[selectedConn].ConnectionString;
}

In this way, after selecting the desired connection in ComboBox , you would have the desired connection in the global variable ComboBox .

    
31.05.2018 / 20:27