日期:2014-05-19  浏览次数:20776 次

c#调用存储过程不能取到返回值问题
///   <summary>
                ///   构建   SqlCommand   对象(用来返回一个结果集,而不是一个整数值)
                ///   </summary>
                ///   <param   name= "connection "> 数据库连接 </param>
                ///   <param   name= "storedProcName "> 存储过程名 </param>
                ///   <param   name= "parameters "> 存储过程参数 </param>
                ///   <returns> SqlCommand </returns>
                private   static   SqlCommand   BuildQueryCommand(SqlConnection   connection,   string   storedProcName,   IDataParameter[]   parameters)
                {
                        SqlCommand   command   =   new   SqlCommand(storedProcName,   connection);
                        command.CommandType   =   CommandType.StoredProcedure;
                        if   (parameters   !=   null)
                        {
                                foreach   (SqlParameter   parameter   in   parameters)
                                {
                                        if   (parameter   !=   null)
                                        {
                                                //   检查未分配值的输出参数,将其分配以DBNull.Value.
                                                if   ((parameter.Direction   ==   ParameterDirection.InputOutput   ||   parameter.Direction   ==   ParameterDirection.Input)   &&
                                                        (parameter.Value   ==   null))
                                                {
                                                        parameter.Value   =   DBNull.Value;
                &n