我在调试没有出现未将对象引用设置到对象的实例。可是当放到服务器时就出现 未将对象引用设置到对象的实例 的错误明明用new 出一个实例了 为什么还有错误?

解决方案 »

  1.   


    欢迎访问我的网站:svn服务器
      

  2.   


    行 37:         ProductsTypeDAL dl = new ProductsTypeDAL();
    行 38: 
    行 39:         List<ProductsType> list =dl.getAllProductsType();
    行 40:         foreach (ProductsType t in list)
    行 41:         {
     
    dl 出现未将对象引用设置到对象的实例。 
      

  3.   


      /// <summary>
            /// 返回所有的实体
            /// </summary>
            /// <returns></returns>
            public List<ProductsType> getAllProductsType()
            {
                SqlParameter[] parm = {
                    new SqlParameter("@sign",SqlDbType.Int)
                };
                parm[0].Value = 0;//存储过程中0为全部 包括现在不能使用的 1为只有使用的
                List<ProductsType> list = new List<ProductsType>();
                SqlDataReader reader = SQLHelper.RunProcedure("p_ProductsType_GetAll", parm);
                while (reader.Read())
                {
                    ProductsType item = new ProductsType();                item.TypeID = reader.GetInt32(reader.GetOrdinal("TypeID"));
                    item.TypeName = reader.GetString(reader.GetOrdinal("TypeName"));
                    item.State = reader.GetString(reader.GetOrdinal("State"));
                    item.Description = reader.GetString(reader.GetOrdinal("Description"));                list.Add(item);
                }
                reader.Close();
                return list;
            }获取数据
      

  4.   


    ProductsTypeDAL dl = new ProductsTypeDAL();
    这句执行没问题?
      

  5.   

    ProductsTypeDAL这个类有没有命名空间啊,引用没引用程序集?
      

  6.   


    服务器没有报什么问题
    这里出现问题 " List<ProductsType> list =dl.getAllProductsType(); "的dl未实例化
      

  7.   

    dl没有获取到值
    ProductsTypeDAL()有问题
      

  8.   


    ProductsTypeDAL()有问题 
      

  9.   

    ProductsTypeDAL 这个类 你是怎么写的
      

  10.   

    很简单啊ProductsTypeDAL 类namespace Leyp.SQLServerDAL
    {
     
        public class ProductsTypeDAL
        {
            public ProductsTypeDAL() { }
      

  11.   


    ProductsTypeDAL dl = new ProductsTypeDAL();
    if(dl!=null)
    {
            List<ProductsType> list =dl.getAllProductsType();
            foreach (ProductsType t in list)
             {
                 ...
             }
             ...
    }
      

  12.   

    dl!=null 是对的 里面 List<ProductsType> list =dl.getAllProductsType();报错
      

  13.   


    汗一个重新编译再传一份
    重载过?
    SQLHELER中的错抛出来了?
      

  14.   

    哈哈 经常出现。。 我的问题一般是得到了一个NULL值的对象 所以报错或者得到对象的类型不是你要插入数据库的类型
      

  15.   

    不是数据库问题。
    重新生成DLL看看,同时判断
    if(dl!=null)
    {
    List <ProductsType> list =dl.getAllProductsType(); 
            foreach (ProductsType t in list) 
            { 
           } 
    }