Solved

asp,net vb.net update command parameters

Posted on 2009-04-08
5
309 Views
Last Modified: 2012-05-06
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

and:

        cmd.Parameters.AddWithValue("@neme", Trim(Txtname.Text))
0
Comment
Question by:rflorencio
  • 3
  • 2
5 Comments
 
LVL 5

Expert Comment

by:mfhorizon
ID: 24096482
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...
0
 
LVL 15

Accepted Solution

by:
NazoUK earned 500 total points
ID: 24097066
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.
0
 
LVL 5

Expert Comment

by:mfhorizon
ID: 24097537
Yes, NazoUK seems to present my example in a theoritical way as well...
0
 
LVL 15

Expert Comment

by:NazoUK
ID: 24098049
Not really, he wanted to know how using AddWithValue was different. You didn't address this point at all.
0
 
LVL 5

Expert Comment

by:mfhorizon
ID: 24104151
Yes, i overlooked last statement of the question, however i answered first 2 perfect.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now