sql - sqlcommand.parameters.add() 和 sqlcommand.parameters.addwithvalue() 有什么区别

标签 sql ado.net

我们可以在将参数传递给 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 the SqlParameterCollection.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/

相关文章:

c# - 无法插入数据库

c# - 为什么人们说 SqlDataReader.GetXXX(i) 比 SqlDataReader[i] 快?

sql - 如何将月份编号转换为oracle中的完整月份名称?

mysql查询返回匹配元素列表的列表

sql-server - SQL Server 连接任意返回 233 或 18456 错误代码

c# - SQL连接到数据库重复

sql - 如何在 MySQL 中获取下一条/上一条记录?

sql - R 向量转化为字符串

mysql - 在MySQL中使用动态SQL(带有查询结果的子查询)

tsql - T-SQL 中的形状查询