Most of the time I access data using stored procedures but at times I use statements which I believe are not vulnerable to SQL injection.
Below is an example I use
protected void Page_Load(object sender, EventArgs e)
{
try
{
int CatID = Request["CatID"];
if (!IsPostBack)
{
getDetails(CatID);
}
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
}
private DataTable getDetails( int CatID)
{
try
{
DataSet ds = new DataSet();
string strSql = "SELECT * FROM TableXYZ WHERE CatID = "+CatID ;
ds = DataProvider.Connect_Select(strSql);
DataTable dt = ds.Tables[0];
return dt;
}
catch (Exception ex)
{
throw;
}
}
I filter my input or query string and then I call getDetails function and pass CatID as parameter to the function & then to SQL statement. Since this is an integer type data is this code vulnerable to SQL injection?
I want to clear my doubt so that I don't use SQL statement like this.
Int.Parse(CatID)? CatID is already (guaranteed to be!) anint(see method signature).