日期:2014-05-18  浏览次数:21210 次

无法将类型“System.Collections.Generic.List<PetShop.Model.Item>”隐式转换为“PetShop.Model.It
public PetShop.Model.Item GetItemById(string ItemId)
   
  {

  string sql = "select item.itemid, item.name, item.listprice, product.name, item.image, product.categoryid, product.productid from item inner join product on item.productid = product.productid where item.itemid = @itemid";
  string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ssa"].ConnectionString;


  List<PetShop.Model.Item> list = new List<PetShop.Model.Item>();
  using (SqlConnection connection = new SqlConnection(connectionString))
  {
  SqlCommand command = new SqlCommand(sql, connection);
  connection.Open();

  command.Parameters.Add("@itemid", SqlDbType.NVarChar).Value = ItemId;

  SqlDataReader reader = command.ExecuteReader();
  while (reader.Read())
  {
  PetShop.Model.Item item = new PetShop.Model.Item()
  {
  ItemId = reader.GetString(0),
  Name = reader.GetString(1),
  Quantity = reader.GetInt32(2),
  ListPrice = reader.GetDecimal(3),
  ProductName = reader.GetString(4),
  Image = reader.GetString(5),
  CategoryId = reader.GetString(6),
  ProductId = reader.GetString(7)
  };
  list.Add(item);

  }
  return list;
  }

  }

------解决方案--------------------
public PetShop.Model.Item GetItemById(string ItemId)
 
=>

public List<PetShop.Model.Item> GetItemById(string ItemId)