Solved

asp,net vb.net update command parameters

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

809 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