public static Product GetProduct(int productID) { dbcon obj = new dbcon(); SqlParameter[] objParams = new SqlParameter[1]; objParams[0] = new SqlParameter("@ProductID", SqlDbType.Int, 4); objParams[0].Value = productID; SqlDataReader reader = obj.ExecuteReader("GetProduct", objParams); Product p = new Product(); while (reader.Read()) { p.ProductID = reader.GetInt32(reader.GetOrdinal("ProductID")); p.CategoryID = reader.GetInt32(reader.GetOrdinal("CategoryID")); p.Name = reader.GetString(reader.GetOrdinal("ProductName")); p.Description = reader.GetString(reader.GetOrdinal("Description")); p.UnitCost = reader.GetDecimal(reader.GetOrdinal("UnitCost")); p.ProductImage = reader.GetString(reader.GetOrdinal("ProductImage")); p.oprice = reader.GetDecimal(reader.GetOrdinal("origionalPrice")); } reader.Close(); return(p); }
public static List <ShoppingCartItem> GetItems(string customerID) { dbcon obj = new dbcon(); SqlParameter[] objParams = new SqlParameter[1]; objParams[0] = new SqlParameter("@CustomerID", customerID); SqlDataReader reader = obj.ExecuteReader("GetCartForCustomer", objParams); List <ShoppingCartItem> objList = new List <ShoppingCartItem>(); while (reader.Read()) { ShoppingCartItem item = new ShoppingCartItem(); item.CustomerID = reader.GetString(reader.GetOrdinal("CustomerID")); item.ProductID = reader.GetInt32(reader.GetOrdinal("ProductID")); item.ProductName = reader.GetString(reader.GetOrdinal("ProductName")); item.buyPrice = reader.GetDecimal(reader.GetOrdinal("origionalPrice")); item.Quantity = reader.GetInt32(reader.GetOrdinal("Quantity")); item.UnitPrice = reader.GetDecimal(reader.GetOrdinal("UnitCost")); objList.Add(item); } reader.Close(); return(objList); }