title: how you retrieve data from a database
body: <p>I have created the classes for the menu items and I cannot figure out how to get a price when someone someone select a pizza from the combobox and selects the toppings. I am getting the pizza prices and the topping price from a database. Here is my pizza Class</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Data.SqlClient;
  using System.Data;
  
  
  namespace ItalianoLIB.BLL
  {
  
     public class Pizza
      {
  
         public string pizzaName { get; set; }
         public string toppingName { get; set; }
         public double toppingPrice { get; set; }
         public double pizzaPrice { get; set; }
  
  
  
      }
  }
  
  
  using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;
  using System.Data.SqlClient;
  
  
  
  
  namespace ItalianoWIN.PLL
  {
  
      public partial class PizzaMenu : Form 
      {
          public string newPizzaName { get; set; }
          public string newToppingName { get; set; }
          public double newToppingPrice { get; set; }
          public double newPizzaPrice { get; set; }
  
          public PizzaMenu()
          {  
  
              InitializeComponent();
          }
  
          private void Pizza_Load(object sender, EventArgs e)
          {
  
              //new connection from the DButils class
              SqlConnection con = new SqlConnection(ItalianoLIB.DLL.DButils.CONSTR);
              con.Open();
  
              //fill Pizza type combo box
              SqlDataAdapter da = new SqlDataAdapter("select * from pizza", con);
              DataTable dt = new DataTable();
              da.Fill(dt);
  
  
  
              for (int i = 0; i &lt; dt.Rows.Count; i++)
              {
               cboPizzaType.Items.Add(dt.Rows[i]["PizzaType"]);
              }
  
  
  
              //fill toppings listbox
              SqlDataAdapter da2 = new SqlDataAdapter("select * from Topping",con);
              DataTable dt2 = new DataTable();
              da2.Fill(dt2);
  
              for (int i = 0; i &lt; dt2.Rows.Count; i++)
              {
                  lstToppings.Items.Add(dt2.Rows[i]["ToppingName"]);
              }
  
  
  
              con.Close();
  
  
          }
  
          private void cboPizzaType_SelectedIndexChanged(object sender, EventArgs e)
          {
  
  
          }
  
  
          private void lstToppings_SelectedIndexChanged(object sender, EventArgs e)
          {
  
          }
  
          private void bnPizOrd_Click(object sender, EventArgs e)
          {
              newPizzaName = cboPizzaType.Text.ToString();
  
  
  
              //Brings the user back to the main form
              this.DialogResult = DialogResult.OK;
          }
  
          private void bnAddTop_Click(object sender, EventArgs e)
          {
  
  
              object obj = lstToppings.SelectedItem;
              lstSelTop.Items.Add(obj);
              lstToppings.Items.Remove(obj); 
  
          }
  
          private void bnDelTop_Click(object sender, EventArgs e)
          {
              object obj = lstSelTop.SelectedItem;
              lstToppings.Items.Add(obj);
              lstSelTop.Items.Remove(obj);
  
          }
      }
  }
  </code></pre>