Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I make accounting app

Need to add class with multiple Connection string

Type 

Public class

database
Database name  BSS_2018, BSS_2019...etc
Database username a
Database password a

Database2017
Database2018
Database2019
etc..



This is good way, but have new year must add string in ALL FORMS in APP.
Need to create class with this data
Some help?

What I have tried:

Using before this way with label

string BSS_2018 = Properties.Settings.Default.BSS_2018CS;
string BSS_2019 = Properties.Settings.Default.BSS_2019CS;
string con;


InitializeComponent();

yearlabel.Text = getYear();



public void PullData()
       {
           if (yearlabel.Text == "BSS_2018")
           {
               con = BSS_2018;
           }
           else if (yearlabel.Text == "BSS_2019")
           {
               con = BSS_2019;
           }



       }
Posted
Updated 14-Jul-19 1:59am
v2
Comments
Richard MacCutchan 14-Jul-19 3:42am    
Create a method or class that takes a single parameter, the year, and returns the correct string(s) for all requirements.
Goran Bibic 14-Jul-19 7:21am    
Yeah. Need example
Richard MacCutchan 14-Jul-19 7:35am    
Use String.Format to create the strings you need, passing in the year number.


String mymethod(int year)
{
string dbName = String.Format("mydb_{0}", year);
return dbName;
}

1 solution

If only the year has to be changed in the connectionstring, you can use .Replace()
C#
string con = Properties.Settings.Default.BSS_2018CS.Replace("2018", "2019");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900