Solved

asp,net vb.net update command parameters

Posted on 2009-04-08
5
319 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

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…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 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