public class ProductsTypeDAL { public ProductsTypeDAL() { }
ProductsTypeDAL dl = new ProductsTypeDAL(); if(dl!=null) { List<ProductsType> list =dl.getAllProductsType(); foreach (ProductsType t in list) { ... } ... }
dl!=null 是对的 里面 List<ProductsType> list =dl.getAllProductsType();报错
欢迎访问我的网站:svn服务器
行 37: ProductsTypeDAL dl = new ProductsTypeDAL();
行 38:
行 39: List<ProductsType> list =dl.getAllProductsType();
行 40: foreach (ProductsType t in list)
行 41: {
dl 出现未将对象引用设置到对象的实例。
/// <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;
}获取数据
ProductsTypeDAL dl = new ProductsTypeDAL();
这句执行没问题?
服务器没有报什么问题
这里出现问题 " List<ProductsType> list =dl.getAllProductsType(); "的dl未实例化
ProductsTypeDAL()有问题
ProductsTypeDAL()有问题
{
public class ProductsTypeDAL
{
public ProductsTypeDAL() { }
ProductsTypeDAL dl = new ProductsTypeDAL();
if(dl!=null)
{
List<ProductsType> list =dl.getAllProductsType();
foreach (ProductsType t in list)
{
...
}
...
}
汗一个重新编译再传一份
重载过?
SQLHELER中的错抛出来了?
重新生成DLL看看,同时判断
if(dl!=null)
{
List <ProductsType> list =dl.getAllProductsType();
foreach (ProductsType t in list)
{
}
}