I need to insert a string into an Sql Command
search.CommandText = "SELECT * FROM Contacts WHERE Name like ' + @person + % + '";
What it the right way of using LIKE in a command?
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.
Should be:
@personis a parameter – you don’t need single quotes around it. You only need to concatenate it with%, which should have quotes.Keep in mind:
"SELECT * FROM Contacts WHERE Name like @person", and have the parameter value contain%(concatenate in C# is simpler to understand).%,_,[and].