473,326 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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 6260
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
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
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
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
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
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
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
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
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
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
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.