How to add initial data to SQLite database?

后端 未结 6 1645
逝去的感伤
逝去的感伤 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:38

    You should check the number of objects inside your database each time you open the database for the first time in your app. Don't forget that user can free all data.

        //Open DataBase
        MyDb.Open();
    
        //Get All List
        MyCursor = MyDb.getAllNames(); //You should have a function to get all the table data
    
        //First Time we open Database, add default Values
        if ( MyCursor.getCount() < 1 )
        {
            AddDefaultValuesToDataBase();
        }
    

    From Here you can continue to get the values again.

    Hope it helps, BR, Adrian.

提交回复
热议问题