Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Setting the paramter size for a SqlParameter

Posted on 2007-11-29
4
Medium Priority
?
227 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 150 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

730 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