请问一下传入一个函数的参数为int型,可不可以直接利用int型参数动态构造sql语句而不用SqlParameter传参数如:
Student GetStudeint(int id)
{
string strSQL = "select * from tbStudent where id=" + id.ToString();
.......
}这样写不知道有没有SQL注入漏洞,因为参数是int型,应该不会有注入吧?
Student GetStudeint(int id)
{
string strSQL = "select * from tbStudent where id=" + id.ToString();
.......
}这样写不知道有没有SQL注入漏洞,因为参数是int型,应该不会有注入吧?
强烈建议
string sql = String.Format("select * from aaaa where id={0}", id);
可读和可维护都好
每次调用就传不同的参数 在用string sql = String.Format("select * from aaaa where id={0}", id);
还可以先有替换
{
string strSQL = "select * from tbStudent where id=" + convert.ToInt32(id.ToString()); .......
} 这样会进行一个强制转换,如果有恶意注入,转换就会失败,从而停止程序运行,不会对数据库有破坏