有这样的一个存储过程:
CREATE PROCEDURE checkstate @param varchar(11)
AS
IF (SELECT state FROM authors WHERE au_id = @param) = 'CA'
   RETURN 1
ELSE
   RETURN 2
问题是我怎样在程序接收到sql返回的值???
用Command.ExecuteScalar()??还是用Command.ecuteNonQuery();??

解决方案 »

  1.   

    int intReturnValue = Command.ecuteNonQuery()
    是这个,但是update 或delete执行后Command.ecuteNonQuery()返回影响的行数,不要误用哦
      

  2.   

    CREATE PROCEDURE get_sales_for_title
    @title varchar(80),   -- This is the input parameter.
    @ytd_sales int OUTPUT -- This is the output parameter.
    AS  -- Get the sales for the specified title and 
    -- assign it to the output parameter.
    SELECT @ytd_sales = ytd_sales
    FROM titles
    WHERE title = @titleRETURN
    GO 
    ///============public override bool ExecuteStoredProc(string pcSPName, ArrayList poParams, ref string pcOutputParamName)
    {
    bool llRetVal = false; if (this._Connection!=null)
    {
    try
    {
    SqlCommand loCommand = new SqlCommand(pcSPName, this._Connection, 
    this._Transaction);
    loCommand.CommandType = CommandType.StoredProcedure;
    foreach (npIdName loParam in poParams)
    {
    SqlParameter loSqlParm = new SqlParameter("@"+loParam.Id, SqlDbType.NChar);
    loSqlParm.Value = loParam.Name;
    loSqlParm.Direction = ParameterDirection.Input;
    loCommand.Parameters.Add(loSqlParm);
    }
    if (pcOutputParamName!="")
    {
    pcOutputParamName = "@"+pcOutputParamName;
    SqlParameter loOutPutParm = new SqlParameter(pcOutputParamName, SqlDbType.NChar);
    loOutPutParm.Direction = ParameterDirection.Output;
    loCommand.Parameters.Add(loOutPutParm);
    } loCommand.ExecuteNonQuery();
    if (pcOutputParamName!="")
    pcOutputParamName = loCommand.Parameters[pcOutputParamName].Value.ToString(); llRetVal = true;
    }
    catch (Exception e)
    {
    this.FireDBConnectionError("ExecuteStoredProc", pcSPName, e.Message);
    }
    } return llRetVal;
    }