我们可以在将参数传递给 sql 查询时同时使用这两种方法吗?
那么它们之间有什么区别呢?
最佳答案
MSDN article on AddWithValue()
解释两者之间的差异。内是对细微差异的解释。
AddWithValue replaces the
SqlParameterCollection.Add
method that takes a String and an Object.The overload of
Add
that takes a string and an object was deprecated because of possible ambiguity with theSqlParameterCollection.Add
overload that takes a String and a SqlDbType enumeration value where passing an integer with the string could be interpreted as being either the parameter value or the corresponding SqlDbType value.Use AddWithValue whenever you want to add a parameter by specifying its name and value.
关于sql - sqlcommand.parameters.add() 和 sqlcommand.parameters.addwithvalue() 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5527949/