Incorrect Syntax Near 's' When Passing String Parameter
In c# I have the following lines of code: string mySqlStmt = 'SELECT CASE WHEN (SELECT COUNT(*) FROM tlGenericName WHERE ( UPPER(ltrim(rtrim(genericName_str))) = '' + this.cmbGen
Solution 1:
Escape the single quotes something like below:
this.cmbGenericName.Text.Trim().ToUpper().Replace("'", "''")
Also as a suggestion as mentioned by Peter in the comment avoid using inline SQL statements to avoid the SQL injection attacks by using the SqlCommand and its parameters!
Post a Comment for "Incorrect Syntax Near 's' When Passing String Parameter"