Click here to Skip to main content
15,889,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
what is the difference between using
C#
cmd.Parameters.AddWithValue(@Name, textbox1.Text);

and
C#
SqlParameter parameter = new SqlParameter(@Name, textbox1.Text)
// and adding Parameter like
cmd.Parameters.Add(parameter);


I really wondered when i see these two different techniques ? Which is useful in real time and what are the pros and cons between them? please Give some valuable information about them?
Posted
Updated 14-Nov-14 0:22am
v4

Two things:
1) The first form is more readable and compact: which helps with maintenance.
And
2) The second form has been superseded by the first form and does not have it's potential problems. For example, see the MSDN documentation: http://msdn.microsoft.com/en-us/library/9dd8zze1(v=vs.110).aspx[^]
 
Share this answer
 
AddWithValue replaces the method Add in the class SqlParameterCollection because of ambiguity.
It is an overload designed to make it easier to write the code.

See: SqlParameterCollection.AddWithValue Method[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900