I\'m trying to get output value from DB via ADO.NET. There\'s a client code:
using (var connection = new SqlConnection(ConnectionString))
{
I had this error occur, supplying a value that had a non-string, but nullable, type. In my case, an int?
. I fixed it by passing in a non-nullable int
instead.
Check MSDN : SqlParameter.Size Property
For bidirectional and output parameters, and return values, you must set the value of Size. This is not required for input parameters, and if not explicitly set, the value is inferred from the actual size of the specified parameter when a parameterized statement is executed.
VarChar and NVarChar are variable width character fields (thus var+char). You have to set the length, otherwise the default is zero.
Incidentally, setting the size property of an output parameter is necessary even if it isn't a string-type parameter. For example, if you are using a System.Data.SqlDbType.Int, you should set the size to be 4.