I Have a WinForm with 2 Text boxes to input ServerName and Database, RadioButtons to switch between providers, and 1 Button to build ConnectionStrings depending of inputs. _ServerName and _DatabaseName are Global variables. I would like to build the connection string outside the Form and get the result returned to a label control in my Form, the code in my external class is as next:
public static string _ServerName { get; set; }
public static string _Base { get; set; }
public static SqlConnection _Con { get; set; }
static void ConOption1()
{
Global._Con = new SqlConnection();
Global._Con.ConnectionString = @"data source=" + Global._ServerName + "; initial catalog=" + Global._Base + "; Integrated Security=True";
}
The code in my form (Form1) is:
private void button1_Click(object sender, EventArgs e)
{
Global._ServerName = textBox1.Text;
Global._Base = textBox2.Text;
ConOption1();
label1.Text = Global._Con.ToString();
}
The problem here is that I cannot call conOption1 from Form1 to get the built string in Label1.text, thanks for your help.