SqlParameterCollection.Add is obsolete and deprecated

前端 未结 1 1444
花落未央
花落未央 2021-01-29 08:44

I am getting squiggly lines underneath the following code

sda2.SelectCommand.Parameters.Add(\"@from\", from);
sda2.SelectCommand.Parameters.Add(\"@to\", to);


        
相关标签:
1条回答
  • 2021-01-29 09:16

    AddWithValue is the method that 'replaced' it:

    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.

    MSDN: SqlParameterCollection.AddWithValue Method

    0 讨论(0)
提交回复
热议问题