Question

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.

Was it helpful?

Solution

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 + "%");

OTHER TIPS

Global.db.Query<Cards>($"select * from Cards where card_name like %{nameTextBox.Text}%");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top