> 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;