SqlParameter.Size - When to use?

  • Thread starter Thread starter Amy L.
  • Start date Start date
A

Amy L.

When using Stored Procedures and SqlParameters when do you need to
specify the SqlParameter.Size property?

From the documentation and examples I have seen where Integers had a
size set and examples where Integers did not have a size set.

When inserting into a text field what would you set the size property too?

Is there an easy way to have the framework determine what the size of
the parameter actually is for non-fixed length items (String, text, etc)?

Thanks
Amy
 
Use this as a rule of thumb: If the stored procedure Parameter declaration
needs a length (as in
@MyString VarChar(20)
)
then you need to pass a length argument to the SqlParameter when setting up
the Parameters collection.
Note that this length is checked when you apply a string to the
variable--you'll throw an exception if it's too long.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant, Dad, Grandpa
Microsoft MVP
INETA Speaker
www.betav.com
www.betav.com/blog/billva
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
 
Back
Top