Johan
Johan

Reputation: 35

Datasources in C#

Long time reader, first time poster.

Background:

We have developed a small application in C# for creating proprietary binary files for use in our embedded system. The application is very simple, just a few textboxes, comboboxes and checkboxes, and a couple of buttons for creating files. It is distributed to our customers as just an .exe file, meaning, no installation is required, and that is how we want it.

Problem:

I have been tasked by our support staff to implement a way to save some settings and load them again. This data should be retained in between runs of the app. The user should be able to save a couple of these under different names.

The question is:

What are my options? So far I have identified 3 possible solutions:

Upvotes: 1

Views: 776

Answers (5)

Khadaji
Khadaji

Reputation: 2167

In the past, I have created a small "settings" class. I have then over ridden the ToString method and also created a parse method.

I have stored each setting in the settings file using a global::System.Collections.Specialized.StringCollection type to store a collection of settings. I use the ToString method to store the setting and the Parse method to read it back in.

Lastly, I use an int type to store the currently selected index.

Upvotes: 0

Henrik
Henrik

Reputation: 3704

The easiest way is to use user or application settings

Add an app.config file to your project and edit the settings like this

<setting name="Setting" serializeAs="String">
   <value>This is the setting value</value>
</setting>

http://msdn.microsoft.com/en-us/library/aa730869(v=vs.80).aspx#settingscs_topic2

Upvotes: 0

CodeMad
CodeMad

Reputation: 948

"C# Settings" should work for you. Have you tried it right? Please see the below links. Hope it helps

Visual Studio Settings file - how does it work?

http://msdn.microsoft.com/en-us/library/aa730869%28VS.80%29.aspx

It worked for me.

Upvotes: 0

Dr Herbie
Dr Herbie

Reputation: 3940

If the data to be saved is small and simple, then I would go for physical files; the overhead in setting up the SQL Server Compact for you application is larger than just serialising a class or struct to XML and saving to file.

On the other hand, if the data becomes more complicated, including one-to-many or many-to-many style of relationship, then you would want to move to the database solution.

To keep flexibility ensure you decouple the save/load code so you can change from file to database if the need arises.

Upvotes: 0

FIre Panda
FIre Panda

Reputation: 6637

You could use an Xml file to save your settings. Your application could load these settings and act accordingly. If you are .Net 4.0, you could LINQ that will make your job pretty easy. Have a look at this.

Upvotes: 2

Related Questions