What's happening?
sqlCommand.CommandText = "SELECT * FROM Customer WHERE Name LIKE @Name;";
sqlCommand.Parameters.AddWithValue("@Name", "%" + searchString + "%");
You can also encode it as follows to avoid formatting the lookup in the first place:
sqlCommand.CommandText = "SELECT * FROM Customer WHERE CHARINDEX(@Name, Name) > 0;";
sqlCommand.Parameters.AddWithValue("@Name", searchString);
If you intend to insist on doing this in an unsafe way, at least double any single quotes found in searchString, for example.
searchString.Replace("'", "''")
source
share