Solved

asp,net vb.net update command parameters

Posted on 2009-04-08
5
311 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

19 Experts available now in Live!

Get 1:1 Help Now