There is no difference in functionality. In fact, both do this:
return this.Add(new SqlParameter(parameterName, value));
The reason they are deprecated in favor of AddWithValue is to add extra clarity, and also because the second parameter is object , which makes it not immediately obvious to some people whose overload was Add and they led to completely different behavior.
Take a look at this example:
SqlCommand command = new SqlCommand(); command.Parameters.Add("@name", 0);
At first glance, it looks like it causes an overload of Add(string name, object value) , but it is not. It causes an overload of Add(string name, SqlDbType type) ! This is because 0 is implicitly converted to enumeration types. So these two lines:
command.Parameters.Add("@name", 0);
and
command.Parameters.Add("@name", 1);
Actually call two different methods. 1 implicitly converted to an enum, so it selects an object overload. Using 0 he selects an overload of the enumeration.
vcsjones Apr 03 '12 at 19:11 2012-04-03 19:11
source share