sqlite-net like statement crashes

橙三吉。 提交于 2019-12-24 02:56:11

问题


I have a SQL statement like this:

Global.db.Query<Cards>("select * from Cards where card_name like ?", nameTextBox.Text);

But I want to add % to both sides like this with the parameter value.

Global.db.Query<Cards>("select * from Cards where card_name like %?%", nameTextBox.Text);

But I'm throwing an error when I try to execute this. Any ideas why its crashing when I use the like statement like this? I ran the same query in my sqlite admin program with the same database and the results came out like they should.


回答1:


But I want to add % to both sides like this with the parameter value.

So do it for the value itself, rather than decorating the parameter in the SQL:

Global.db.Query<Cards>("select * from Cards where card_name like ?",
    "%" + nameTextBox.Text + "%");



回答2:


Global.db.Query<Cards>($"select * from Cards where card_name like %{nameTextBox.Text}%");


来源:https://stackoverflow.com/questions/16705558/sqlite-net-like-statement-crashes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!