[英]Sqlite Like query xamarin forms
I'm trying to make a like in xamarin, but what the query returns to me is just a number, I already tested it in DBowser sqlite, and it works, but not here. 我正在尝试在xamarin中创建一个类似的查询,但是查询返回给我的只是一个数字,我已经在DBowser sqlite中对其进行了测试,并且它可以正常工作,但不适用于这里。 What will be the mistake?
怎么了?
Query 询问
public Task<Produtos> GetProdutosAsyncBy(String searchField)
{
string searchNoSpaces = searchField.Replace(" ", "%");
var get_docnumb = database.ExecuteScalarAsync<Produtos>("SELECT *" +
" FROM Produtos WHERE Design LIKE '%" + searchNoSpaces + "%'");
return get_docnumb;
}
Call Query 通话查询
public async void SearchProdutoQuery ()
{
var qwe = App.Database.GetProdutosAsyncBy(searchBar_produtos.Text).Result;
}
You can use Scalar to return something as below: 您可以使用Scalar返回以下内容:
public int GetCountProdutosAsyncBy(String searchField)
{
string searchNoSpaces = searchField.Replace(" ", "%");
var get_docnumb = database.ExecuteScalarAsync<Produtos>("SELECT COUNT(*) FROM Produtos WHERE Design LIKE '%" + searchNoSpaces + "%'");
return get_docnumb;
}
But to solve your problem you can't use Scalar, you need to QUERY and to avoid SQL injection you should use parameter: 但是要解决您的问题,您不能使用Scalar,需要查询,并且要避免SQL注入,您应该使用参数:
public Task<Produtos> GetProdutosAsyncBy(String searchField)
{
string searchNoSpaces = searchField.Replace(" ", "%");
var get_docnumb = database.Query<Produtos>("SELECT * FROM Produtos WHERE Design LIKE ?", "%" + searchNoSpaces + "%");
return get_docnumb;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.