c# - Dynamic SQL query causes "Unclosed quotation mark" error -


I am getting this error:

After the character string, the quotation mark symbol '' .

With the following code:

  lSQL = "Remove from TBL corrections where courseCode = '" + aCourseCode + "' ';  < / Pre> 

where lSQL is a local variable and aCourseCode is a store value. Any suggestions?

You should use always queries, or your code is sensitive to errors worse than SQL injection attacks. When building questions Use the never string constant in the form this is the correct way:

  (var conn = new SqlConnection (ConnectionString)) by using (var cmd = conn. CreateCommand ()) {conn.Open (); Cmd.CommandText = "Remove from TBL corse where course code = @ course seed"; Cmd.Parameters.AddWithValue ("@ courseCode", aCourseCode); Int Removed RowsCount = cmd ExecuteNonQuery ();}   

will ensure that even if there are some escape and dangerous characters in the aCourseCode variable, they will be properly controlled.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -