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 返回输出值,我想从调用函数的位置返回

4

1 回答 1

1

在此语句后添加以下代码

dtOrder = db.ExecuteDataSet(cmd);

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

or

recordcount = convert.ToInt32(cmd.Parameters["@RecordCount"]);
于 2013-11-21T07:34:31.213 回答