Why does is think the column is the parameter value

前端 未结 2 1382
余生分开走
余生分开走 2021-01-26 17:28

I get SQLite.SQLiteException: \'no such column: osborne\' when I run this code. osborne is my search term, not the column. The column is LastName. Here is the queryasync code

2条回答
  •  长情又很酷
    2021-01-26 17:48

    you need to delimit string parameters in SQL queries

    return Database.QueryAsync
        ($"SELECT * FROM [DataItem] WHERE [LastName] = '{s}'");
     
    

    as pointed out in the comments, parameterized queries are more secure

    return Database.QueryAsync
        ("SELECT * FROM [DataItem] WHERE [LastName] = ?", s);
    

提交回复
热议问题