locked
Save a data and load a data without Database RRS feed

  • Question

  • Hello People,

    I want save a data and when i close the aplication and open after the data is load.

    I don't want to use Database.

    How i can save and load a data without Database ?

    i can save and load a file but is not safe.

    Thank you

    Saturday, October 3, 2020 11:51 PM

Answers

  • Hello People,

    Thank you for your answares

    i will read all

    I stopped the project temporarily but I intend to get back to it soon.

    Thank you very mutch for all

    • Marked as answer by Malainho Saturday, October 31, 2020 1:25 PM
    Saturday, October 31, 2020 1:24 PM

All replies

  • i can save and load a file but is not safe.

    Your choice is a file or a database.


    • Edited by DA924x Sunday, October 4, 2020 2:52 AM
    Sunday, October 4, 2020 2:51 AM
  • The three top choices are, XML, CSV, JSON for super simple data storage. 

    Issues for the above.

    • No built in way to properly handle primary keys. Primary keys are fundamental to finding data, you must handle this yourself.
    • High level, dealing with relationships. Generally speaking storing data seldomly is stored in one table (in a database) and even though you can do relations with the above is harder.
    • Backup/restoring data, databases have it but none of the above.

    If I absolutely had to pick one it would be storing data in a json file, second choice would be XML. I highly recommend you consider using a database such as SQL-Server Express edition or Microsoft Access.

    No I don't have a code sample so no need to ask.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Sunday, October 4, 2020 3:27 AM
  • In addition, consider binary serialisation too:

    // the data class

    [Serializable]

    class MyData

    {

           public string Name;

           public int Year;

    }

    . . .

    // saving

    {

           MyData data = new MyData( );

           data.Name = "Sarah";

           data.Year = 2100;

           string filepath = "MyFile.data";

           var bf = new BinaryFormatter( );

           using( var s = File.OpenWrite( filepath ) )

           {

                 bf.Serialize( s, data );

           }

    }

    // loading

    {

           MyData data = null;

           string filepath = "MyFile.data";

           var bf = new BinaryFormatter( );

           using( var s = File.OpenRead( filepath ) )

           {

                 data = (MyData)bf.Deserialize( s );

           }

           Console.WriteLine( data.Name );

           Console.WriteLine( data.Year );

    }

    Regardless the method used, take into consideration future updates of data structure, when the previously saved version of files or tables becomes obsolete.



    • Edited by Viorel_MVP Sunday, October 4, 2020 4:19 PM
    Sunday, October 4, 2020 1:27 PM

  • I don't want to use Database.

    How i can save and load a data without Database ?

    i can save and load a file but is not safe.


    Define what you consider "not safe". 

    Do you mean other people can read the data in the file(s) and you don't want 
    that to happen? In which case you want encryption or obfuscation of the data.

    Or do you mean "not safe" in terms of backups, fall-backs or roll-backs, etc.?

    Or do you mean "not safe" in terms of ensuring data integrity?

    Your requirements will usually define and/or constrain the viable options.

    - Wayne

    Sunday, October 4, 2020 7:04 PM
  • Hi Malainho,

    How is the question going? Did you solve your problem? If your question has been answered then please click the "Mark as Answer" Link at the bottom of the correct post(s), so that it will help other members to find the solution quickly if they face a similar issue.

    Best Regards,

    Xingyu Zhao

     

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, October 21, 2020 2:16 AM
  • Hello People,

    Thank you for your answares

    i will read all

    I stopped the project temporarily but I intend to get back to it soon.

    Thank you very mutch for all

    • Marked as answer by Malainho Saturday, October 31, 2020 1:25 PM
    Saturday, October 31, 2020 1:24 PM