Monday, March 9, 2020

C# - How call stored proc with output/return parameter ?

public static string GetStatistics() {
  string value = "";

  SqlCommand command = DB.SPPrepare( "GetStatisticsAsString" );
            
  command.Parameters.Add( new SqlParameter( "@catalog", "HYG" ) );
  command.Parameters.Add( new SqlParameter( "@catalogDSO", "MYDSO" ) );
  SqlParameter par = new SqlParameter( "@output", System.Data.SqlDbType.NVarChar, 2048 );
  par.Direction = System.Data.ParameterDirection.Output;
  command.Parameters.Add( par );

  command.ExecuteNonQuery();

  value = (string)command.Parameters[ "@output" ].Value;

  return value;
}

No comments:

Post a Comment