0

It recommends me to use .AddWithValue instead. Now having been learning to use mysql in .net over the last few days and looking around the web for information, I was under the impression that .AddWithValue can sometimes produce non-optimal results because it has to guess the type of the property while .Add is strongly typed.

Has something changed since those posts/articles were created? Why is it now deprecated?

user81993
  • 6,167
  • 6
  • 32
  • 64
  • Apparently it has been deprecated for ages, since [this question was asked before in 2012](http://stackoverflow.com/questions/13580993/mysqlcommand-command-parameters-add-is-obsolete). – GolezTrol Sep 06 '15 at 21:25
  • Use pocoorm to connect with database. its easy & first. – jewelhuq Sep 06 '15 at 21:47

2 Answers2

1

Well, I thought this question was a duplicate, but actually it isn't. The other question just states you should use AddWithValue. The question why it is deprecated is answered in the documentation:

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.

Community
  • 1
  • 1
GolezTrol
  • 114,394
  • 18
  • 182
  • 210
0

Please read this article, advising you against using AddWithValue:

https://blogs.msmvps.com/jcoehoorn/blog/2014/05/12/can-we-stop-using-addwithvalue-already/

It says basically that AddWithValue could sometimes incorrectly infer the correct type. Use Add instead.

Adam Calvet Bohl
  • 1,009
  • 14
  • 29