>> 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 >>>>
>p.Direction = ParameterDirection.Output;
>//etc <------- This one :-}
>p.Value = cVal3;
I think you have this working now anyway but here's a complete example. GivenCREATE PROCEDURE [dbo].[MyProc] > @Param3 nvarchar(30) OUT >AS >BEGIN > SET @Param3 = 'Hello ' + @Param3 > RETURN >ENDThen
SqlConnection conn = new SqlConnection(); > conn.ConnectionString = s; > conn.Open(); > > System.Data.Common.DbCommand command = new SqlCommand(); > System.Data.IDbDataParameter p = command.CreateParameter(); > > p.ParameterName = "@Param3"; > p.Direction = ParameterDirection.InputOutput; > p.Value = "World"; > p.DbType = System.Data.DbType.String; > p.Size = 30; > command.Parameters.Add(p); > > command.Connection = conn; > command.CommandType = System.Data.CommandType.StoredProcedure; > command.CommandText = "MyProc"; > command.ExecuteNonQuery(); > string result = (string) command.Parameters["@Param3"].Value;Yes, I see that I missed specifying the Size of the passed parameter. Once I added this (Size) the code works. Except (I have not tested it today) yesterday the call to ExecuteNonQuery() was returning -1. Maybe it is normal but I thought it should be 0. I will recheck.