1

User inputs financial year like 2012-2013, 2013-2014, 2014-2015,.... Based on the financial year input by the user in the text box txtFinYear.text different database should be connected through conn.string. My database names in my MySQL are db_2012_2013, db_2013_2014, db_2014-2015, ....

I am new to C#. At present a single string to connect to a single database defined in app.config file within my c# solution.

Please help

4
  • What have you done so far ? Please post some code and/or a real question. Commented Dec 11, 2014 at 20:02
  • Usually you would have several connection strings defined in an app config. There are answers that can help you. Commented Dec 11, 2014 at 20:03
  • This question is really not related to mysql or databases. It's more about taking text from an input and using it to generate a different string (which just happens to be a connection string). It is a possible duplicate of stackoverflow.com/questions/3965503/string-manipulations Commented Dec 11, 2014 at 20:07
  • Sort of tangential, but if you have a predefined set of dates (2012-2013, 2013-2014, etc) it's significantly easier to provide the users a means to select one, rather than making them input a date into a text box. In terms of your connection conundrum, add the additional connection strings to your app config and implement an if() or switch()... this should be very easy. Commented Dec 11, 2014 at 20:14

1 Answer 1

1

You could create the connection string dynamically, instead of fetching it from app.config as like,

MySqlConnectionStringBuilder connStr = new MySqlConnectionStringBuilder();
connStr.Server = "YourServer";
connStr.UserID = "UserId";
connStr.Password = "Pwd";
connStr.Database = txtFinYear.text; //Verify before assigning

MySqlConnection con = new MySqlConnection(connStr.ToString());

Hope this helps...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.