Search code examples
c#.netwindows-forms-designer

Is it possible to make a log in form, that saves its data after the program closes and reopens other than using SQL?


I want to create a C# windows form application login form that allows the user to create an account and was hoping to save that account locally (in a file in current pc) for academic purposes. Different solutions that I have encountered have all suggested to use mySQL to save the file. Although it is very much effective, I am hoping to find an alternative solution.

I have already tried using mySQL but I'm looking for an alternative.


Solution

  • Yes, you can absolutely just save the information locally.

    The simplest option is to use a serialization library, like system.Text.Json. Just create an object to represent the data, and ask the library to serialize it to a file. You would typically store this file in a subfolder under localapplicationData, at least if it is managed by the application.

    You can decide when to save/load the data:

    1. The application starts/closes (with the risk of data loss if the application crashes)
    2. When the user explicitly saves/loads the file
    3. Whenever the data changes

    My recommendation would be to start storing data in a file, since that is typically simpler than a database. But you might want to have an interface for the part that does the storage, so that the majority of your code don't have to care how it is stored. That should help you move to a database if your requirements grow.