Solved

Setting the paramter size for a SqlParameter

Posted on 2007-11-29
4
225 Views
Last Modified: 2010-04-21
I have this question about whether or not it's prefered to set the size of a SqlParamter.
I usually do something like this:
SqlCommand cmd = new SqlCommand(StoredProcName,Connection);
cmd.Parameters.Add("@SomeParamter", SqlDbType.NVarChar).Value = SomeValue;

Is it recommended that I set the size of the paramter like this:
cmd.Parameters.Add("@SomeParamter", SqlDbType.NVarChar, 100).Value = SomeValue;
 
or it's the same? And also, if the paramter is NText how would I set the size for it?

Thanks in advance
0
Comment
Question by:JessyEzzy
[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
  • 2
  • 2
4 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20372621
if you do not set the size explicitely, it will be "set" implicitely by the value you assign to the parameter.
0
 
LVL 3

Author Comment

by:JessyEzzy
ID: 20384108
Set implicitly at which stage? And does setting or not setting the size affects performance?

Thanks
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 50 total points
ID: 20385397
>Set implicitly at which stage?

at "this" stage:
.Value = SomeValue;

which is "after" this part:
cmd.Parameters.Add("@SomeParamter", SqlDbType.NVarChar)

>And does setting or not setting the size affects performance?
no. but it does "increase" the readability, if you consistently use the same size there as in the procedure, as that way, you could see more easily when the value you try to pass is larger than what the procedure will "accept".
0
 
LVL 3

Author Closing Comment

by:JessyEzzy
ID: 31411630
Thanks
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
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…

710 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