6

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

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

this means it will not check wht data is been supplied to it. it will give the data directly to query if the parameter is int and i am supplying it string it will directly take it it will not give any error

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.