C# sqlparameter type length ?

H

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
 
K

Karl Seguin

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top