我从数据库返回带output参数的存储过程的时候用了一个实体类来传递output参数
ALTER procedure [dbo].[jz_cheshi]
(@count int output,@input int=null)
as
set @count=(select count(*) from [user])
if(@input is not null)
begin
select top(@input) companyName from [user] 
end
else
begin
select companyName from [user]
end
go
实体类: public class OutPut
        private int _count;
        private int _countAll;
        private int _clockCount;
        private int _notClockCount;
        private int _showCount;
        private string _outCode;
        private int _outInt;
        private int _returnValue;
        /// <summary>
        /// 存储过程output参数类 索引
        /// </summary>
        /// <param name="index">output参数名称</param>
        /// <returns></returns>
        public object this[string index]
        {
            get {
                if (index == "@count") { return _count; }
                else if (index == "@countAll") { return _countAll; }
                else if (index == "@clockCount") { return _clockCount; }
                else if (index == "@notClockCount") { return _notClockCount; }
                else if (index == "@showCount") { return _showCount; }
                else if (index == "@outInt") { return _outInt; }
                else if (index == "ReturnValue") { return _returnValue; }
                else if (index == "@outCode") { return _outCode; }
                else throw new Exception();
            }
             set {
                 if (index == "@count") { _count = (int)value; }
                 else if (index == "@countAll") { _countAll = (int)value; }
                 else if (index == "@clockCount") { _clockCount = (int)value; }
                 else if (index == "@notClockCount") { _notClockCount = (int)value; }
                 else if (index == "@showCount") { _showCount = (int)value; }
                 else if (index == "@outInt") { _outInt = (int)value; }
                 else if (index == "ReturnValue") { _returnValue = (int)value; }
                 else if (index == "@outCode") { _outCode = (string)value; }
                 else
                     throw new Exception();
            }
       }
数据库操作:
        public DataTable RunProcDA(string ProcName, SqlParameter[] pram,out Model.OutPut Output)
        {
            SqlDataAdapter da = CreateProcAdapter(ProcName, pram);
            DataTable dt = new DataTable();
            da.Fill(dt);
            DataClose();
            Model.OutPut output = new Model.OutPut();
            if (da.SelectCommand.Parameters.Count > 0)
            {
                for (int i = 0; i < da.SelectCommand.Parameters.Count; i++)
                {
                    if (da.SelectCommand.Parameters[i].Direction.ToString() == "Output"||da.SelectCommand.Parameters[i].Direction.ToString()=="ReturnValue")
                    {
                        string outputName = da.SelectCommand.Parameters[i].ParameterName.ToString();
                        output[outputName] = da.SelectCommand.Parameters[i].Value;
                        string xxx = output[outputName].ToString();
                    }
                }
            }
            Output = output;
            return dt;
        }
调用:
        public DataTable cheshi( out Model.OutPut output)
        {
            SqlParameter[] pram = { sqlHelp.CreateOutParam("@count", SqlDbType.Int, 0),
                                  sqlHelp.CreateInParam("@input",SqlDbType.Int,0,5)};
            Model.OutPut a = new Model.OutPut();
            DataTable dt= sqlHelp.RunProcDA("jz_cheshi", pram,out a);
            output=a;
            return dt;
        }我感觉这样的问题很多,希望大家指点