hi,
I have a windows form with a combo box on it. The combo box has the words Production and Development in it. If the user selects "Production", I need my C# code to point to the Production database. If the user selects "Development", I need my C# code to point to the Development database. Can someone please tell me how to do this?
thanks,
Sharon
Loading
Sam HobbsPosted Feb 10, 2012, 3:10 AM
Sharon ChapmanPosted Feb 9, 2012, 11:39 AM
This is how I solved the problem:
string cs = "";
if (comboBox1.SelectedIndex == 0)
{
cs = @"server=JITC-PC\GEOINT;database=Production_GEOINT;integrated security=SSPI";
}
else if (comboBox1.SelectedIndex == 1)
{
cs = @"server=JITC-PC\GEOINT;database=DEV_GEOINT;integrated security=SSPI";
}
The button code looks like this:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
Thanks,
Sharon
Sam HobbsPosted Feb 8, 2012, 4:52 PM
The database is determined by the connection string or the database property of the connection. You do not specify how you are connecting to the database. It is frustrating to answer questions that do not specify inportant details because we can easily guess wrong what it is that they need and then the person asking the question says we are wrong. So please understand that if my answer is not relevant, it probably means you need to clarify womething.
You can build a connection string dynamically and change the database it specifies; there are various ways to do that. Or you can change the Database Property of the SqlConnection class if you are connecting to the database that way. If you are using a Typed Database (a TableAdapter or the Entity Framework) then you can probably modify the database property somehow.
Or you can have two separate connection strings. Or you could have two separate TableAdapters or Entity Framework tables. It depends on what you are using; what your organization is using.