我正在使用sqlite-net作为wp8。我试图在表中插入一行但是我得到一个运行时错误,说该列不存在。当我在行前面放置一个断点并通过数据库变量时,我可以看到表和列,所以我不确定它们是怎么回事。这是代码:
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; }
}
答案 0 :(得分:0)
您在SQL查询中提到了两列,然后是三列:
[...] (desc, date) [...] (calories = 100, desc = 'food', date = '5/26/13')
正确的查询是:
insert into Entry (calories, desc, date) values (100, 'food', '5/26/13')
答案 1 :(得分:0)
试
db.BeginTransaction();
db.Insert(new Entry() {
calories = 100,
desc ='food',
date = '5/26/13'
});
db.Commit();