mapping to a varchar

Posted on 2004-10-27
Last Modified: 2010-04-23
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?
Question by:philjh
    LVL 15

    Expert Comment

    ' assume cmd is a SqlCommand object.
    Dim p As New SqlParameter("@Parameter", SqlDbType.VarChar, 16)

    You can specify the length as the third parameter, in my example I used 16.
    LVL 7

    Expert Comment

    You shouldn't...just use something like:

    oComm.Parameters.Add(New SqlParameter("@varAdjustment", SqlDbType.varchar)).Value = "Blah"

    Author Comment

    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.
    LVL 7

    Accepted Solution

    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 most programs do.

    Author Comment

    Sorry for the delay. Got sidetracked...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    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…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    877 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

    13 Experts available now in Live!

    Get 1:1 Help Now