简体   繁体   中英

Persisting data between sessions in C#

All,

I have a test program that will serialize test subjects for some research sessions. I'll be running the program at different times, so I need this data to persist. It will be a simple ID number in 001 format (two leading zeros until 10, one leading zero until 100) and will max out at 999. How would I accomplish this in C#? Ideally, it starts up, reads the persistent data, then starts registering new test subjects at the latest number. This number will then be used as a primary key to recognize the test subjects in a database. I've never done anything remotely like this before, so I'm clueless as to what I should do.

EDIT:

I probably should have clarified... there are multiple databases. One is a local SQLite file that holds the test subject's trial data (the specific data from each test). The other is a much larger MySQL database that holds more general information (things about the test subject relevant to the study). The MySQL database is remote and data from the application is not directly submitted to it... that's handled by another application that takes the SQLite file and submits that data to the MySQL database. The test environment is variable and may not have a connection to the MySQL database. As such, it's not a viable candidate for holding such data as I need the ID numbers each time I start the program, regardless of the connection state to the MySQL database. The SQLite files are written after program execution from a text file (csv) and need to contain the ID number to be used as a primary key, so the SQLite database might not be the best candidate for storing the persistent data. Sorry I didn't explain this earlier... it's still early in the day :P

If these numbers are used in a database as the index, why not check the database for the next number? If 5 subjects have been registered already, next time just check the database, get the max for the index and add 1 for the next subject. Once you insert that subject, you can add 1 again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM