1
I have a function that adds a filter to the SqlDataSource
. That expression contains a LIKE
at the consultation. However, if the person places a character such as '
, an error (which evidences SQL Injection).
string cliente = TB_Cliente.Text;
string retorno = "CodOrdemServico = CodOrdemServico ";
if (cliente.Length > 0)
{
retorno += String.Format("AND Cliente LIKE '%{0}%'", cliente);
}
DS_Grid.FilterExpression = retorno;
How can I escape the LIKE
above?
your
DS_Grid
is a Sqldatasource?– Pablo Tondolo de Vargas
Bobby Tables sends his regards
– Maniero
Yes, @Pablotondolodevargas
– Wallace Maxters
@Maniero I get depressed seeing so many questions with SQL Injection, the worst they still teach in college using string concatenation.
– Pablo Tondolo de Vargas
@Maniero this system was not made by me. I am giving maintenance :... I am ashamed to use this Web Forms :|
– Wallace Maxters
See this: https://msdn.microsoft.com/en-us/library/xt50s8kz.aspx
– Maniero