-1
private static SqlParameter AddNewParameterToCommand(SqlCommand command,
    string name, object value, bool isOutputParameter)
{       
    SqlParameter parm = new SqlParameter();
    parm.ParameterName = name;
    parm.Value = value;
    command.Parameters.Add(parm);

    if (isOutputParameter == true)
    {
        command.Parameters.Add(new SqlParameter("@parameter"));
    }

    return parm;
}

Here is what I was trying to setup but have been unable to: If the isOutputParameter parameter is true, the new SqlParameter object is set up to accept data back from the database when the command is run.

Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541
shenn
  • 859
  • 4
  • 17
  • 47

2 Answers2

3
private static SqlParameter AddNewParameterToCommand(SqlCommand command,
    string name, object value, bool isOutputParameter)
{
    SqlParameter parm = new SqlParameter();
    parm.ParameterName = name;
    parm.Value = value;

    if (isOutputParameter)
    {
        parm.Direction = ParameterDirection.InputOutput;
    }

    command.Parameters.Add(parm);

    return parm;
} 

Ref: SqlParameter.Direction

Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541
1

You need to set SqlParameter.Direction attribute.

if (isOutputParameter)
   {
    param.Direction=ParameterDirection.Output;
   }
KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
  • Thanks! What would I need to do If this SQLcommand were to have a single output paramater and I wante d to get it's value? – shenn Jan 24 '12 at 01:43