返回ref类型值

时间:2013-11-08 12:00:34

标签: asp.net c#-4.0

如何返回从我的商店程序返回的ref类型值。以下是我的功能

  public DataSet GetOrderListByClient(int pageindex,int PageSize,string ordernum, string subOrderNum, string referance, DateTime startdate, DateTime endDate, Int32 clientid,ref int recordcount)
    {
        DataSet dtOrder = new DataSet();

        //  const string SQL_STATEMENT = @" Your SP Name";


        // Connect to database.
        Database db = DatabaseFactory.CreateDatabase(CONNECTION_NAME);
        using (DbCommand cmd = db.GetStoredProcCommand("GetOrderListByClient"))
        {
            if (pageindex == 0)
                db.AddInParameter(cmd, "@PageIndex", DbType.Int32, pageindex);
            if(PageSize == 0)
                db.AddInParameter(cmd, "@PageSize", DbType.String, PageSize);
            // Set parameter values.
            if (ordernum != string.Empty)
                db.AddInParameter(cmd, "@orderNumber", DbType.String, ordernum);
            if (subOrderNum != string.Empty)
                db.AddInParameter(cmd, "@subOrderNumber", DbType.String, subOrderNum);
            if (referance != string.Empty)
                db.AddInParameter(cmd, "@ref", DbType.String, referance);
            db.AddInParameter(cmd, "@OrderstartDate", DbType.Date, startdate);
            db.AddInParameter(cmd, "@OrderEndDate", DbType.Date, endDate);
            db.AddInParameter(cmd, "@ClientId", DbType.Int32, clientid);
            db.AddInParameter(cmd, "@RecordCount",DbType.Int32, 5);
            cmd.Parameters["@RecordCount"].Direction = ParameterDirection.Output;
            try
            {
                dtOrder = db.ExecuteDataSet(cmd);
            }
            catch
            {
                // TODO: Handle exception here. Remove any un-used try-catch blocks if 
                //       exception handling is not required.
                throw new NotImplementedException("Exception handling not implemented.");
            }
        }

        return dtOrder;
    }

我在这里称这个功能

DataSet _ds = _odDac.GetOrderListByClient(1, 10, txtOrderNumber.Text, txtOrderSubNumber.Text, txtRef.Text, Convert.ToDateTime(txtFirstDate.Text), Convert.ToDateTime(txtLastDate.Text), clientid, ref count);

我希望我的storeprocdure返回输出值,我想从我调用函数的地方返回

1 个答案:

答案 0 :(得分:1)

在此声明之后加下以下代码

dtOrder = db.ExecuteDataSet(cmd);

recordcount = (int)cmd.Parameters["@RecordCount"];

or

recordcount = convert.ToInt32(cmd.Parameters["@RecordCount"]);