Access application settings from code
Hi , I stored my connection in application settings i.e. project > properties> settings tab. Now i need to access the connection string from code. How do i do it ?? any help is appreciated, red
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Ken LinderPosted Feb 9, 2007, 11:09 AM
Just access the settings like this...
Properties.Settings.Default.SettingName
Substitute your setting name for SettingName. That will return a string.
Now, a cool thing you can do with settings is save them! Just create a setting in the same place you set up your connection string. Say for example, you create a setting called UserEmail. Here's how you would save to it.
Properties.Settings.Default.UserEmail = "[email protected]"; // sample e-mail
Properties.Settings.Default.Save();
Now, to retrieve it & display on a label, do this...
label1.Text = Properties.Settings.Default.UserEmail;
It WILL persist these settings from one run time to another. This is MUCH easier than using regristy settings, IMHO!!!
red manPosted Feb 3, 2007, 9:56 PM
tsosane shabePosted Feb 3, 2007, 5:37 PM
Can you please help me with simple c# code to create poll and be able to show number of people voted , Results in pecentages and results in bar graphs