private static IList<ProductInfo> GetOrdersBySql(string safeSQL) { List<ProductInfo> list = new List<ProductInfo>(); try { SqlDataReader read = DBhelperSQL.GetReader(safeSQL); if (read.HasRows) { while (read.Read()) { ProductInfo product=new ProductInfo(); //OrderInfo order = new OrderInfo(); //order.CustomerName = read.GetString(0); //order.OrderDate = read.GetDateTime(1); product.ProductId = read.GetString(2); product.ProductName = read.GetString(3); product.Price = read.GetInt32(4); product.Imagepath = read.GetString(5); product.Count = read.GetInt32(6); product.Description = read.GetString(7); list.Add(product); } } read.Close(); return list; } catch (Exception ex) { Console.WriteLine(ex.Message); throw ex; } } 就是把我注释的内容也添加到list当中去
ProductInfo 中增加两个字段CustomerName,OrderDate。Info中的字段不一定要和数据库一样,根据需要可以做适当扩展
SqlDataReader 的 NextResult(),然后用同一个 reader 再 Read()