Reputation: 3
When running the below query getting the above error,
String sql = "((NAME= '" + sReceipts[0] + "' ) OR (SECTION IN ('RECEIPT', 'PROJECT') AND NAME IS NULL))";
sReceipts[0]
value is 'Tom's' (with an APOSTROPHE) gives the error
But if sReceipts[0] = 'Ann' no error occur.
Tried to solve with String.Format but I couldn't. What is the best approach please?
Upvotes: 0
Views: 725
Reputation: 10320
You should use parameterised queries such as the below:
OracleCommand oraCommand = new OracleCommand("SELECT YourColumn FROM
YourTable WHERE ((NAME= :receiptName ) OR (SECTION IN ('RECEIPT', 'PROJECT') AND NAME IS NULL))", db);
oraCommand.Parameters.Add(new OracleParameter("recieptName", sReceipts[0]));
See MSDN OracleCommand.Parameters Property if you are using the Microsoft class and OracleParameterCollection for the equivalent Oracle parameter collection.
Upvotes: 4
Reputation: 1769
I would wrap sReceipts[0] in a regular expression that replaces the apostrophe with two apostrophes.
Upvotes: -2