Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is difference betwn sqlcommand.parameters.add() and sqlcommand.parameters.addwithvalue()

Tags:

sql

ado.net

we can use both the method while passing parameters to sql query ? then wht is the difference between them?

like image 304
CHANDRAHAS Avatar asked Apr 03 '11 06:04

CHANDRAHAS


1 Answers

The MSDN article on AddWithValue() explains the difference between the 2. Within is the explaination on the subtle differences.

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.

like image 139
p.campbell Avatar answered Oct 01 '22 20:10

p.campbell