how string.format() can help to avoid using “+” in such statement:
string statement =" SELECT DISTINCT titel as linieName" +
" FROM qry_Forecast_Taktzeiten" +
" WHERE linieName LIKE 'lin%';";
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The statement above the
+is used to concatenate seveal strings you created to make your code more readable.String.Formatwill not help you here!To avoid the string concatenation you could do the following:
If you want to replace the ‘lin’ with some variable you have you can use:
or
However, all of the methods above using string replacement ({0}) bear the risk of an SQL injection attack if the “lin%” is obtained from a user entry.
So the best bet is to use: