This is for Chris. Escaping characters may work. If the person is clever, the are some ways around it.
For instance.
-- Use Adventure works
use adventureworks2012
go
Say, I know you are replace a single quote with two, your chosen solution on the answere line. Enter the following
Bothell'; GRANT CONTROL TO [adw_user];PRINT' at a text box.
This boils down to this @fld variable.
-- Declare the vars
declare @sql nvarchar(max);
declare @fld varchar(128) = 'Bothell''; GRANT CONTROL TO [adw_user];PRINT''';
print @fld
-- Perform some injection
set @sql = 'select * from [Person].[Address] where City = ' +
char(39) + @fld + char(39);
print @sql
exec sp_executesql @sql
There you have SQL Injection.
select * from [Person].[Address] where City = 'Bothell';
GRANT CONTROL TO [adw_user];PRINT''
(26 row(s) affected)
http://www.w3schools.com/sql/sql_injection.asp
Quote from W3Schools - The only proven way to protect a web site from SQL injection attacks, is to use SQL parameters.
A very good read. Check out link to truncation attacks. In short, parameterization makes sure the input is treated as a literal, not code.
http://blogs.msdn.com/b/raulga/archive/2007/01/04/dynamic-sql-sql-injection.aspx