Skip to content Skip to sidebar Skip to footer

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!

Solution 2:

Try it using string interpolation :

var number = 2;
var exampleString = $"Number is : {number}";

Post a Comment for "Incorrect Syntax Near 's' When Passing String Parameter"