2013-05-26 78 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();