asp,net update command parameters

When i use an sql command to update a table with parameters like:

"update product set name=@name ....

Watt is the difference between:
       cmd.Parameters.Add("@name", SqlDbType.VarChar, 60)
       cmd.Parameters("@name").Value = TxtMatricula.Text


        cmd.Parameters.AddWithValue("@neme", Trim(Txtname.Text))
Who is Participating?
NazoUKConnect With a Mentor Commented:
AddWithValue will use type inference to format the way the parameter is passed to the stored procedure or query based on the type of the variable you pass it. So if you pass in a datetime variable it will assume the parameter should be an sql datetime type and will format it accordingly. Mostly it works ok but in some situations you might find that it doesn't do what you expect.
Using the first way you specify explicitly what the datatype of the parameter should be giving you more safety and control at the expense of a bit more typing.
cmd.Parameters.Add("@name", SqlDbType.VarChar, 60) normally uses when your command is refering to a stored procedures, so you are adding a parameter object to you command

However cmd.Parameters("@name").Value = TxtMatricula.Text you are setting the value of the parameter as what is input in TxtMatricula.Text.

Unless you create a variable (parameter) how can you add value to add... it's that simple...
Yes, NazoUK seems to present my example in a theoritical way as well...
Not really, he wanted to know how using AddWithValue was different. You didn't address this point at all.
Yes, i overlooked last statement of the question, however i answered first 2 perfect.
All Courses

From novice to tech pro — start learning today.