parameter best practices

  • Thread starter Thread starter ChrisB
  • Start date Start date
C

ChrisB

Hello:

I just completed reading "Best Practices for Using ADO.NET" in MSDN
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadonet/h
tml/adonetbest.asp) and was surprised to find no discussion on ADO
parameters.

Specifically, I was wondering how much information should be provided when
instantiating a parameter. The simplest approach seems to work just fine:
SqlParameter sqlParameter = new SqlParameter("@ConsumerID", ConsumerID);

Under what circumstances should additional information such as parameter
datatype, size, etc. be included? Is there any benefit to including this
information?

Thanks for any input.

Chris
 
I'm under the impression that it's better to be explicit when it comes to
defining parameters. This eliminates the need to add extra code behind the
scenes to manually coerce the type at runtime. I would say that datatype is
a minimum and size should always be used with strings or VarBinary. Of
course, numeric types should include precision and scale as well. That said,
the amount of time saved in overhead will be very small on a per-reference
basis.

hth

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
When manually creating Insert and Update command objects for a dataadapter,
I find it frustrating to include the datatype and datasize for each
parameter I add to the command object. Is there a better way to do this?
 
Well, there are wizards and drag-and-drop techniques that can generate this
code for you... but don't you get paid by the line?

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
Thanks

PS (My boss likes to think in terms of negative lines per hour (but also
hates code dependancy on wizards)
 
Back
Top