Fork me on GitHub

李可

导航

string[1]:size 属性具有无效大小值0

截图 使用存储过程返回多个字符串参数

程序

     public class EventStatisticsDAL
    {

        public static void GetCount(string code, out string SC, out string DC, out string SSC, out string RPC)
        {
            SqlParameter[] parameter = new SqlParameter[] { 
                
                  new SqlParameter("@DistrictCode",SqlDbType.NVarChar),
                  new SqlParameter("@SC",SqlDbType.NVarChar,50),
                  new SqlParameter("@DC", SqlDbType.NVarChar,50),
                  new SqlParameter("@SSC", SqlDbType.NVarChar,50), 
                  new SqlParameter("@RPC", SqlDbType.NVarChar,50), 
            };
            parameter[0].Value = code;
            for (int i = 1; i < parameter.Length; i++)
            {
                parameter[i].Direction = ParameterDirection.Output;
            }

            List<Self_EventCount> countList = new List<Self_EventCount>();
           SqlHelper.GetTable("SelectEventCount", CommandType.StoredProcedure, parameter);
           SC = Convert.ToString(parameter[1].Value);
           DC = Convert.ToString(parameter[2].Value);
           SSC = Convert.ToString(parameter[3].Value);
           RPC = Convert.ToString(parameter[4].Value);
        }
    }

解决方案:输出参数需指定长度

分析:输出参数为字符串的时候,需要指定其大小

posted on 2016-04-12 15:36  李可在江湖  阅读(877)  评论(0编辑  收藏  举报