繁体   English   中英

Windows Phone上的SQLite查询

[英]Sqlite query on windows phone

我有这段代码

    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”不是列名...

我的查询错了吗?

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM