>>>>Hi,
>>>>
>>>>This is a continuation of the thread where I am trying to get the value of OUTPUT parameter when calling a stored procedure. The stored procedure is very simple and has one OUTPUT parameter where the value is set to something like 'ABCD' (I tried, '1234', and so on).
>>>>
>>>>The problem is that the code below, when gets the value of parameter only shows 1 character. E.g. 'A' or '1', and so on.
>>>>
>>>>Here is the summary of the code (basically copy of what Viv suggested in the other thread):
>>>>
>>>> System.Data.Common.DbCommand command = new SqlCommand();
>>>> System.Data.IDbDataParameter p = command.CreateParameter();
>>>> p.ParameterName = "@Param3";
>>>> p.Direction = ParameterDirection.Output;
>>>> p.Value = cVal3;
>>>> command.Parameters.Add(p);
>>>>int RetValue = command.ExecuteNonQuery()
>>>> var v = command.Parameters["@Param3"].Value;
>>>>// the value 'v' has 'A' or '1' but never the entire string
>>>>
>>>>
>>>>Do you see where could be the problem? TIA.
>>>
>>>You need to define size of the parameter. Also, is the declaration of this parameter correct in the sp? Can you show how it is declared there?
>>
>>This is how the SP looks like:
>>
>>MyProc
>> @Test char(5) = '' OUTPUT
>>BEGIN
>> set @Test = 'ABCD'
>> RETURN
>>END
>>
>>
>>And when I test this SP from a query it works.
>>
>>What do you mean "define size of the parameter"?
>
>You need to define type and size of the parameter.
>See this sample
>
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparameter.size.aspx>
>Set size to 5 for your case.
>Also, I suggest to define direction as InputOutput and initialize with empty value.
Thank you. I will follow your suggestion. I was using direction as Output so that could be it.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham