How to add initial data to SQLite database?

后端 未结 6 1845
逝去的感伤
逝去的感伤 2021-02-14 07:04

I need to add initial values to SQLite database, once application is started first time. How should I do it?

6条回答
  •  被撕碎了的回忆
    2021-02-14 07:52

    One time or first-load requirements like this are common.

    1) Set a flag variable named FIRSTLOAD and set it to True. Be sure to save this variable to isolated storage in the device to read back each time the application is started. 2) Create a method which checks the value of FIRSTLOAD and only executes if FIRSTLOAD is true. Place your code which 'add[s] initial values to SQLite database' here. Then set the FIRSTLOAD variable to false. This way it will only execute the code once!

    Boolean FIRSTLOAD= new Boolean("true");
    
    void SetInitialValues()
    {
       if(!FIRSTLOAD)
          return;
    
       // insert your code to run only when application is started first time here
    
    
       FIRSTLOAD = False;
    }
    

提交回复
热议问题