简体   繁体   中英

Cannot create table SQLite Windows 8

I cannot create a table "IF NOT EXISTS" using SQLite Metro and Windows 8. If I copy the "db" to the application.local folder, I can add, edit delete records. It will created the db, but no table is created. I have checked my DDL with an external tool and it appears correct.
Below is my code :

private void InitData()
    {
        ListBox1.Items.Clear();

        Database db = new Database(Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "bppro.db"));

        Statement stm;
        stm = db.PrepareStatement("CREATE TABLE IF NOT EXISTS vitals (_id integer primary key autoincrement, creationdate text,weight text,pulse text,sys text,dia text");
        stm.Execute();
        stm.Dispose();

        string temp = System.DateTime.Now.Ticks.ToString();

        byte[] binaryData = new byte[100];
        stm = db.PrepareStatement("INSERT INTO vitals (creationdate,weight,pulse) VALUES (?,?,?)");
        stm.BindParamText(1, System.DateTime.Now.ToString());
        stm.BindParamInt(2, 35);
        stm.BindParamInt(3, 60);
        stm.Execute();
        stm.Dispose();

        long insertedRowId = db.LastInsertRowId;

        stm = db.PrepareStatement("SELECT * from vitals");
        while (stm.GetNextRow())
        {
            string createdate=stm.GetTextAt(1);
            string weight = stm.GetTextAt(2);
            string pulse = stm.GetTextAt(3);
            ListBox1.Items.Add(createdate.ToString()+"  "+weight.ToString()+"  "+pulse);
        }
        stm.Dispose();
   }

Thanks, any help or pointers appreciated.

Is this a Windows Store App? If so, you need to be using the WinRT version of SQLite as the File IO APIs have changed.

See my answer to a similar question here: https://stackoverflow.com/a/14469080/68230

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