Ejemplo n.º 1
0
 public Product GetProduct(int ID)
 {
     SqlConnection con = new SqlConnection(connectionString);
     SqlCommand cmd = new SqlCommand("GetProductByID", con);
     cmd.CommandType = CommandType.StoredProcedure;
     cmd.Parameters.AddWithValue("@ProductID", ID);
     
     try
     {
         con.Open();
         SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow);
         if (reader.Read())
         {
             // Create a Product object that wraps the 
             // current record.
             Product product = new Product((string)reader["ModelNumber"],
                 (string)reader["ModelName"], (decimal)reader["UnitCost"],
                 (string)reader["Description"], 
                 (string)reader["ProductImage"]);
             return product;
         }
         else
         {
             return null;
         }
     }
     finally
     {
         con.Close();
     }
 }
Ejemplo n.º 2
0
		public ICollection<Product> GetProducts()
		{			
			SqlConnection con = new SqlConnection(connectionString);
			SqlCommand cmd = new SqlCommand("GetProducts", con);
			cmd.CommandType = CommandType.StoredProcedure;

            ObservableCollection<Product> products = new ObservableCollection<Product>();
			try
			{
				con.Open();
				SqlDataReader reader = cmd.ExecuteReader();
				while (reader.Read())
				{
					// Create a Product object that wraps the 
					// current record.
                    Product product = new Product((string)reader["ModelNumber"],
                        (string)reader["ModelName"], (decimal)reader["UnitCost"],
                        (string)reader["Description"], (string)reader["CategoryName"],
                        (string)reader["ProductImage"]);
					// Add to collection
					products.Add(product);
				}
			}
			finally
			{
				con.Close();
			}

			return products;
		}
Ejemplo n.º 3
0
 public Product GetProduct(int ID)
 {
     DataSet ds = StoreDB2.ReadDataSet();
     DataRow productRow = ds.Tables["Products"].Select("ProductID = " + ID.ToString())[0];
     Product product = new Product((string)productRow["ModelNumber"],
             (string)productRow["ModelName"], (decimal)productRow["UnitCost"],
             (string)productRow["Description"], (string)productRow["CategoryName"],
             (string)productRow["ProductImage"]);            
     return product;
 }