MS SqlServer参数化

nian203344 2010-09-26 11:27:38
/// <summary>
/// 根据类别获得随机数据列表
/// </summary>
public DataSet GetList(int count, string pids, string sex)
{
StringBuilder strSql = new StringBuilder();
SqlParameter[] arrParam;
strSql.Append("select top " + @count + " * from products");

if (pids != string.Empty && pids != "0")
strSql.Append(" where producttype_id in( " + @pids + ")");

strSql.Append(" order by newid()");

arrParam = new SqlParameter[]
{
new SqlParameter("@count",count),
new SqlParameter("@pids",pids)
};

return SqlHelper.ExecuteDataset(CommandType.Text, strSql.ToString(), arrParam);
}
为了防止注入用参数化这样做和直接拼SQL有区别吗?能达到防止注入的效果么?SqlParameter到底做了些什么?
...全文
76 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
dawugui 2010-09-26
  • 打赏
  • 举报
回复
SQL注入专题
http://topic.csdn.net/u/20081205/09/3dd06076-bcbe-45d4-998c-8999fdbe6fae.html
hao1hao2hao3 2010-09-26
  • 打赏
  • 举报
回复
防注入可以在前台用脚本做一些特殊字符的过滤处理。

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧