我无法使用 SQLite Metro 和 Windows 8 创建表“IF NOT EXISTS”。如果我将“db”复制到 application.local 文件夹,我可以添加、编辑删除记录。它将创建数据库,但没有创建表。我用外部工具检查了我的 DDL,它看起来是正确的。
下面是我的代码:
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();
}
谢谢,任何帮助或指针表示赞赏。