title: How to use a Datareader Inside a Class using C#
body: <p>I have <code>SqlDataReader</code> that was sitting in a page's code behind (well actually a web user control). I'd like to move this code to a separate class which the user control calls. But how do I bind the data from the class to the on page repeater?</p>
  
  <p>Is this an acceptable concept?</p>
  
  <p>Here's my code moved to a class:</p>
  
  <pre><code>public class ShoppingCart
  {
      public ShoppingCart(int ShoppingCartHeadID)
      {
          SqlConnection conn;
          SqlCommand comm;
          SqlDataReader reader;
  
          conn = new SqlConnection(iceConns.iconn);
  
          comm = new SqlCommand("Ordering.sl_ShoppingCartContents", conn);
          comm.CommandType = CommandType.StoredProcedure;
          comm.Parameters.Add(new SqlParameter("@shoppingCartHeadID", SqlDbType.Int));
          comm.Parameters["@shoppingCartHeadID"].Value = ShoppingCartHeadID;
  
          try
          {
              conn.Open();
              reader = comm.ExecuteReader();
              Cart.DataSource = reader; //This ain't gonna work!
              if (reader.HasRows)
              {
                  Cart.DataBind(); //This ain't gonna work!
                  varCartStatus = true;
              }
              reader.Close();
          }
          catch
          {
              //Error trapping
          }
          finally
          {
              conn.Close();
          }
      }
  }
  </code></pre>
  
  <p>Any help would be greatly appreciated.</p>