kishore_peddi
asked on
Difference between "Add" and "AddWithValue" for command parameters ...
Hi,
I have the following info:
SqlCommand cmd = new SqlCommand("StoredProcedur eName", cn);
cmd.Parameters.AddWithValu e("@typ", dt);
What is the difference between "Add" and "AddWithValue" ? Means:
cmd.Parameters.Add(.....)
cmd.Parameters.AddWithValu e(.....)
And when to use what ? Can you please explain me in simple terms with simple examples ?
Thanks
I have the following info:
SqlCommand cmd = new SqlCommand("StoredProcedur
cmd.Parameters.AddWithValu
What is the difference between "Add" and "AddWithValue" ? Means:
cmd.Parameters.Add(.....)
cmd.Parameters.AddWithValu
And when to use what ? Can you please explain me in simple terms with simple examples ?
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Can you please make this simple to understand with a small example ? I want to understand the basics behind the scenes.
AddWithValue replaces the SqlParameterCollection.Add method that takes a String and a 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.
For SqlDbTypeXml enumeration values, you can use a string, an XML value, an XmlReader derived type instance, or a SqlXml object.
Appreciate your time, patience and help !!
Thanks
AddWithValue replaces the SqlParameterCollection.Add
For SqlDbTypeXml enumeration values, you can use a string, an XML value, an XmlReader derived type instance, or a SqlXml object.
Appreciate your time, patience and help !!
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
is equivalent to:
cmd.Parameters.Add("@typ",
The later one is deprecated in favor of the first, as it is clearer.
Specify the data type of the parameter if you know it. Example:
cmd.Parameters.Add("@typ",