Questions tagged «sql-parametrized-query»

6
如何创建参数化的SQL查询?我为什么要?
我听说“每个人”都在使用参数化的SQL查询来防止SQL注入攻击,而不必验证用户的每一项输入。 你怎么做到这一点?使用存储过程时,是否会自动获得此信息? 因此,我的理解是非参数化的: cmdText = String.Format("SELECT foo FROM bar WHERE baz = '{0}'", fuz) 这将被参数化吗? cmdText = String.Format("EXEC foo_from_baz '{0}'", fuz) 还是我需要像这样做一些更广泛的事情,以保护自己免受SQL注入? With command .Parameters.Count = 1 .Parameters.Item(0).ParameterName = "@baz" .Parameters.Item(0).Value = fuz End With 除了安全方面的考虑之外,使用参数化查询还有其他优势吗? 更新:这篇很棒的文章与Grotok引用的问题之一相关联。 http://www.sommarskog.se/dynamic_sql.html
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.