【问题标题】:Sqlite query on windows phonewindows phone 上的 Sqlite 查询
【发布时间】:2014-02-06 12:39:41
【问题描述】:

我有这段代码

    premios pre = new premios() { name = "premio1", link = "http://www.host.com/image.png" };
                if (DB.CheckPremios(pre))
{//does stuff
}

CheckPremios 功能就是这个:

public bool CheckPremios(premios pre) 
        {
            using (var db = new SQLiteConnection(dbPath))
            {
                var existing = db.Query<premios>("select * from premios where name =" + pre.name);
                if (existing != null)
                {
                    return true;
                }
            }
            return false;
        }

附加信息:没有这样的列:premio1

它抱怨“Premio1”列不存在,尽管“Premio1”不是列名...

我的查询错了吗?

【问题讨论】:

    标签: c# xaml windows-phone-8 sqlite


    【解决方案1】:

    您的查询调用不正确,主要是因为您没有将查询值括在引号中,因此 SQLite 会将其视为与列名进行比较。我建议不要在自己中添加单引号,而是通过指定要进行替换的位置并传入参数列表来使用查询调用,例如:

    var existing = db.Query<premios>("select * from premios where name = ?", pre.name);
    if (existing != null)
    {
        return true;
    }
    

    【讨论】:

      猜你喜欢
      • 2015-12-07
      • 1970-01-01
      • 1970-01-01
      • 2013-05-20
      • 2014-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-04
      相关资源
      最近更新 更多