If the string company
contains an apostrophe, this will cause an error.
Example: Company name like "William's store".
How to build an SQLite Query that will handle this kind of problem using SQLite-Net api.
I am using SQLite-Net api and I tried both and they did not work. In SQLite-Net api, I think there is no Parameters. What other alternative that I can use? private async void GetCustomerVATGroup(string Company) { 1) string strChkName = Company.Replace("'", "''"); // or Company.Replace("'","\'"); var allUsers = await db.QueryAsync<Customer>( "Select * From Customer Where CompanyName ='" + strChkName + "'"); 2) var allUsers = await db.QueryAsync<Customer>( "Select * From Customer Where CompanyName =''" + Company + "''"); }
From SqlLite Documentation:
So you can escape it with a string replace but the best way to query a db is to avoid string concatenation for avoiding Sql injection.
The best practice is to use Parameterized Querys
In sqllite-net they are passed as argument with the method: