• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

mapping to a varchar

I have a parameter in a stored proc of type varchar. I create a sqlparameter to map to the varchar parameter. When do I have to specify the size of the parameter?
0
philjh
Asked:
philjh
  • 2
  • 2
1 Solution
 
Timbo87Commented:
' assume cmd is a SqlCommand object.
Dim p As New SqlParameter("@Parameter", SqlDbType.VarChar, 16)
cmd.Parameters.Add(p)

You can specify the length as the third parameter, in my example I used 16.
0
 
natlozCommented:
You shouldn't...just use something like:

oComm.Parameters.Add(New SqlParameter("@varAdjustment", SqlDbType.varchar)).Value = "Blah"
0
 
philjhAuthor Commented:
Thanks for the response. I can see that I can use the length, yet natloz suggests that I shouldn't. Why? I am trying to understand if there is a rule about when I should and when I shouldn't.
Thanks.
0
 
natlozCommented:
As far as I have seen the length has not made a difference in my applications. It more than likely just uses a smaller amount of memory when you leave it wide open....as most programs do.
0
 
philjhAuthor Commented:
Sorry for the delay. Got sidetracked...
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now