?
Solved

asp,net vb.net update command parameters

Posted on 2009-04-08
5
Medium Priority
?
325 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month11 days, 20 hours left to enroll

752 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