YosiFZ
YosiFZ

Reputation: 7900

C# Winform database

I am building a Winform application that need a database.

The database needs to save an array of items of a custom class:

Name
Date
Duration
Artist
Genre

If I should build the database using a file that every time, when I increase the array, I will save. Is there wait time to save an array of 300 or so items?

And the second database is to use SQL.

What is the difference between them? And what should I use?

Upvotes: 0

Views: 2154

Answers (3)

T.S.
T.S.

Reputation: 19350

File vs database? - it is easy. What is database - it is a file. Only it has an engine that knows how to manipulate that file. If you use file, you suddenly need to think, "what if?". What if file gets corrupted during write. Or what if computer shuts down in the middle of write? DBMS takes care of this issues by issuing all sorts of mechanisms such as uncommitted data files, etc. Now you will need to provide this mechanism yourself.

This is why you should write to file only non-critical data. For example, some user settings. Because if you lost that file, user can re-size controls again but no data will be at loss. Or log file is another good use of file. Because if you lose a log, you can live without. But if you lose months of worth of data...

In your case, I don't know, how user history is important. 300 items is not a large array. You can use XML by creating an object (class) and mark its properties with XML attributes and then use XML serializer to serialize your history into XML http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx

But if it is going to grow and you not planning to age some of it and delete, look into RDBMS.

Upvotes: 0

Kjartan
Kjartan

Reputation: 19111

As someone mentioned in a comment, SQLite should work very well for this type of scenario.

If you think your data set will remain fairly small, you might consider XML, or a file, or something else if you think that would be quicker/easier.

In any case, I would strongly recommend that you hide your storage-logic behind an interface, and call only that from the winforms part of your application. This way you will be able to replace your storage-solution later if you should need to.

Update in response to comment: The reason for using SQLite instead of another DB System is that SQLite can be integrated directly into your application. Other DBMS`s will typically be external systems, that you just connect to from within your app.

A quick google search will provide you lots of info, such as this short article about using SQLite within a C# application.

Upvotes: 2

user2463711
user2463711

Reputation:

I think you have to think about the futured size of your data.

If you know that i future the data will grow up exponentially, i think you have to use a database System like SQL.

Otherwise if it is only for a few records, you can use a XML File instead.

If you are using a MS SQL Database, you can open a Connection while saving your data, and write it with a sqladapter into the database.

If you are using a XML file instead, you can use the XMLSerializer class for serialization of your own Business object.

Upvotes: 0

Related Questions