473,503 Members | 9,057 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# sqlparameter type length ?

hoz
Hi ,
i have a complex ideas about sqlparameter lenght . lets say i have the
following code
mycom.Parameters.Add("@sip",SqlDbType.NVarChar);
mycom.Parameters["@sip"].Value = siparisid ;

in the stored procedure : create proc SP @kid int , @sip nvarchar(50) as
....

as you have seen , i dont specify parameter lenght in C# . Why ? because
when some changes occurs in db , i only make change in stored procedure.

Does it decrease performance ? and which one is better to use : 1- using
parameter lenght in c# , 2 - using parameter lenght in sp , 3- both of them
.. And why ?

thanks for your help


Nov 19 '05 #1
2 6271
Hoz:
If you don't specify the length, .net will go to some length to figure it
out. It does so based on the type...if it's a varchar/char/nchar/nvarchar/
it gets the length of the string and uses that.

In other words, specifying a length will be faster..but I wouldn't say much
faster...the code .net goes through to figure out the length isn't all that
trivial though, so it's a hard question to answer.

If you are really curious, get Lutz Reflector and open up the SqlParameter's
ActualSize property, you'll see what it's doing when you don't specify the
length..

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"hoz" <as*@me.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
Hi ,
i have a complex ideas about sqlparameter lenght . lets say i have the
following code
mycom.Parameters.Add("@sip",SqlDbType.NVarChar);
mycom.Parameters["@sip"].Value = siparisid ;

in the stored procedure : create proc SP @kid int , @sip nvarchar(50) as ...

as you have seen , i dont specify parameter lenght in C# . Why ? because
when some changes occurs in db , i only make change in stored procedure.

Does it decrease performance ? and which one is better to use : 1- using
parameter lenght in c# , 2 - using parameter lenght in sp , 3- both of them . And why ?

thanks for your help

Nov 19 '05 #2
hoz
thanks for the answer

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:#5**************@TK2MSFTNGP09.phx.gbl...
Hoz:
If you don't specify the length, .net will go to some length to figure it
out. It does so based on the type...if it's a varchar/char/nchar/nvarchar/ it gets the length of the string and uses that.

In other words, specifying a length will be faster..but I wouldn't say much faster...the code .net goes through to figure out the length isn't all that trivial though, so it's a hard question to answer.

If you are really curious, get Lutz Reflector and open up the SqlParameter's ActualSize property, you'll see what it's doing when you don't specify the
length..

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3102
by: Kenneth | last post by:
Can anyone explain me why it is neccesary to include SqlDbType to the SqlParameter. In every example I see, it is done, but no one explaines why. I have for example a date I want to save into my...
3
2435
by: jiangyh | last post by:
hi everyone: SqlParameter class has a property that is DbType looks like following source public DbType DbType { get { // TODO: Add DBParameter.DbType getter implementation return new...
0
382
by: None | last post by:
Hi, I have to update my table using SqlParameter. Below is my code for update. cmdText = "update docs set Content = @content where DirName='" + DirName.Replace("'","''") + "' and...
4
4325
by: Jason Huang | last post by:
Hi, I want to use the Sqlparameter and SqlDataAdapter to update my data, and the data will be updated based on two TextBoxes txtCustName and txtCustAddress. Thanks for help. Jason
5
8281
by: Jason Huang | last post by:
Hi, The SqlParameter myPM =new SqlParameter("@Address", txtAddress.Text) is working for update, but SqlParameter myPM =new SqlParameter ("@Address",SqlDbType.NVarChar,90,txtAddress.Text) is...
3
2741
by: Stacey Levine | last post by:
I have a webservice that has the below procedure. Basically a procedure to called a stored procedure and return the results. When I try to call the webservice from my program I get the error. Both...
6
7824
by: Tim Zych | last post by:
' Declare a new parameter object Dim param() As SqlParameter = New SqlParameter(0) {} ' Set this to null and make it an InputOutput parameter param(0) = New SqlParameter("@Something, DBNull.Value)...
3
1608
by: wackyphill | last post by:
There are sever overloads and ways of adding to the SqlCommand's Parameters collection. They all specify the parameters name. But some also supply a SqlDbType and a length. Does anyone know the...
1
3670
by: rogerford | last post by:
Hi, I am trying to retrieve a value from database, based on that value I want to insert records into DB.Let’s say I am retrieving tsmid which serves as the output parameter in the stored procedure....
0
7193
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
6975
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4992
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.