2013-05-26 75 views
0

我正在使用sqlite-net for wp8。我試圖插入一行到表中,但我得到一個運行時錯誤,說該列不存在。當我在行的前面放置一個斷點並通過數據庫變量時,我可以看到表格和列,所以我不知道發生了什麼。下面是代碼:sqlite表列沒有顯示

db.BeginTransaction(); 
       db.Query<Entry>("insert into Entry(desc, date) values (calories = 100, desc = 'food', date = '5/26/13')"); 
       db.Commit(); 

public class Entry 
{ 
    [SQLite.AutoIncrement, SQLite.PrimaryKey, SQLite.Column("id")] 
    public int id { get; set; } 

    [SQLite.Column("calories")] 
    public int calories { get; set; } 

    [SQLite.Column("desc")] 
    public string desc { get; set; } 

    [SQLite.Column("date")] 
    public string date { get; set; } 
} 

enter image description here enter image description here

回答

0

你提到的兩列,然後分三路在您的SQL查詢:

[...] (desc, date) [...] (calories = 100, desc = 'food', date = '5/26/13') 

正確的查詢是:

insert into Entry (calories, desc, date) values (100, 'food', '5/26/13') 
+0

我修正了它,但仍然是相同的錯誤。即使這仍然告訴我卡路里不存在:「插入入口值(卡路里= 100,desc ='食物',日期='5/26/13')」 – shady

+0

@AaronKerti:其實,我從來沒有見過這種查詢方式:INSERT INTO表VALUES(column = value)'。你確定這是對的嗎? – Otiel

0

嘗試

db.BeginTransaction(); 
db.Insert(new Entry() { 
        calories = 100, 
        desc ='food', 
        date = '5/26/13' 
      }); 
db.Commit();