Use Type
Use Type
The Parameters collection in the Database Engine provides type checking and length validation. If you
use the Parameters collection, input is treated as a literal value instead of as executable code. Another
benefit of using the Parameters collection is that you can enforce type and length checks. Values outside
the range trigger an exception. The following code fragment shows using the Parameters collection:
myCommand.SelectCommand.CommandType = CommandType.StoredProcedure;
SqlDbType.VarChar, 11);
parm.Value = Login.Text;
In this example, the @au_id parameter is treated as a literal value instead of as executable code. This
value is checked for type and length. If the value of @au_id doesn't comply with the specified type and
length constraints, an exception is thrown.
Stored procedures might be susceptible to SQL injection if they use unfiltered input. For example, the
following code is vulnerable:
SqlDataAdapter myCommand =
If you use stored procedures, you should use parameters as their input.