C# sqlparameter type length ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • hoz

    C# sqlparameter type length ?

    Hi ,
    i have a complex ideas about sqlparameter lenght . lets say i have the
    following code
    mycom.Parameter s.Add("@sip",Sq lDbType.NVarCha r);
    mycom.Parameter s["@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




  • Karl Seguin

    #2
    Re: C# sqlparameter type length ?

    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
    Programming blog exploring Zig, Elixir, Go, Testing, Design and Performance



    "hoz" <ask@me.com> wrote in message
    news:%23EdiDK2E FHA.936@TK2MSFT NGP12.phx.gbl.. .[color=blue]
    > Hi ,
    > i have a complex ideas about sqlparameter lenght . lets say i have the
    > following code
    > mycom.Parameter s.Add("@sip",Sq lDbType.NVarCha r);
    > mycom.Parameter s["@sip"].Value = siparisid ;
    >
    > in the stored procedure : create proc SP @kid int , @sip nvarchar(50)[/color]
    as[color=blue]
    > ...
    >
    > 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[/color]
    them[color=blue]
    > . And why ?
    >
    > thanks for your help
    >
    >
    >
    >[/color]


    Comment

    • hoz

      #3
      Re: C# sqlparameter type length ?

      thanks for the answer

      "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
      wrote in message news:#5HxFg2EFH A.2828@TK2MSFTN GP09.phx.gbl...[color=blue]
      > 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[/color]
      varchar/char/nchar/nvarchar/[color=blue]
      > it gets the length of the string and uses that.
      >
      > In other words, specifying a length will be faster..but I wouldn't say[/color]
      much[color=blue]
      > faster...the code .net goes through to figure out the length isn't all[/color]
      that[color=blue]
      > trivial though, so it's a hard question to answer.
      >
      > If you are really curious, get Lutz Reflector and open up the[/color]
      SqlParameter's[color=blue]
      > 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/
      >
      >[/color]


      Comment

      Working...