Friday, April 10, 2009

Value of output parameter truncates.Why?

why value of output parameter truncated in asp.net?? Here is the possibel reason.....
In database programming with SQL-Server and C# Some time we use output parameters to get value From database to C# variable.
There is one constructor of sql parameter which takes two arguments.
(1)parameter name.(2)Default value.

SqlParameter sp = new SqlParameter("@Name","");

When you provide default value and you are not providing Size of parameter Default size will be the length of default value.
In above case size of parameter will be 1. So sql will return only single character as output.
To avoid this problem you have to provide size of output parameter in C#.

sp.Size = 5;

Thanks.