这两个类型应该如何转换?
Product_Info
System.Collections.Generic.IList<Product_Info>我想要的效果如下 IList<Product_Info> list = ProductManager.GetProductBySmallClassId(diaozhuiId);//---------------------下边是参考---------------------------
[Serializable]
public class Product_Info
{
public Product_Info()
{
}
private int id; //商品编号 public int Id
{
get { return id; }
set { id = value; }
}
//....................................... public static IList<Product_Info> GetProductBySmallClassId(int SmallClassId)
{
IList<Product_Info> list=new List<Product_Info>();
string sqlStr = "select top 10 Id,Pro_Name,Pro_ImagePath,Pro_RealPrice,Pro_MarketPrice from Product_Info where SmallClass_Id=@SmallClass_Id";
SqlParameter[] para ={
new SqlParameter("@SmallClass_Id",SqlDbType.Int)
};
para[0].Value = SmallClassId;
using (SqlDataReader sdr = new DBHelp().GetReader(sqlStr, CommandType.Text, para))
{
while (sdr.Read())
{
Product_Info product = new Product_Info();
product.Id = sdr.GetInt32(0);
product.Pro_Name = sdr.GetString(1);
product.Pro_ImagePath = sdr.GetString(2);
product.Pro_RealPrice = sdr.GetDecimal(3);
product.Pro_MarketPrice = sdr.GetDecimal(4);
list.Add(product);
}
}
return list;
}
Product_Info
System.Collections.Generic.IList<Product_Info>我想要的效果如下 IList<Product_Info> list = ProductManager.GetProductBySmallClassId(diaozhuiId);//---------------------下边是参考---------------------------
[Serializable]
public class Product_Info
{
public Product_Info()
{
}
private int id; //商品编号 public int Id
{
get { return id; }
set { id = value; }
}
//....................................... public static IList<Product_Info> GetProductBySmallClassId(int SmallClassId)
{
IList<Product_Info> list=new List<Product_Info>();
string sqlStr = "select top 10 Id,Pro_Name,Pro_ImagePath,Pro_RealPrice,Pro_MarketPrice from Product_Info where SmallClass_Id=@SmallClass_Id";
SqlParameter[] para ={
new SqlParameter("@SmallClass_Id",SqlDbType.Int)
};
para[0].Value = SmallClassId;
using (SqlDataReader sdr = new DBHelp().GetReader(sqlStr, CommandType.Text, para))
{
while (sdr.Read())
{
Product_Info product = new Product_Info();
product.Id = sdr.GetInt32(0);
product.Pro_Name = sdr.GetString(1);
product.Pro_ImagePath = sdr.GetString(2);
product.Pro_RealPrice = sdr.GetDecimal(3);
product.Pro_MarketPrice = sdr.GetDecimal(4);
list.Add(product);
}
}
return list;
}
编译器错误消息: CS0266: 无法将类型“System.Collections.Generic.IList<yjzb.Model.Product_Info>”隐式转换为“System.Collections.Generic.IList<Product_Info>”。存在一个显式转换(是否缺少强制转换?)
yjzb.Model.Product_Info
Product_Info不是同一个类
var list = ProductManager.GetProductBySmallClassId(diaozhuiId);
与其这样,不如返回DataTable,在前台直接用DataTable接收、
yjzb.Model.Product_Info
Product_Info
这两个类上面按F12,你就会发现 会打开两个类,然后看namespace