C#•Bind Your ADO.NET Data

Listing 3. Use a Crystal Reports CrystalReportViewer object to bind your ADO.NET data. Once you retrieve the desired information into a data set, binding it to the Crystal Reports viewer is as simple as binding it to an ASP.NET data grid.

public class PrintingWithCrystal : System.Web.UI.Page
{
protected SqlDataAdapter sqlDataAdapter1;
protected SqlCommand sqlSelectCommand1;
protected SqlConnection sqlConnection1;
protected CrystalDecisions.Web.CrystalReportViewer 
   CrystalReportOrders;
protected VSM102004.OrderDetailsForOrder 
   dsReportOrderDetails;
protected SqlParameter ParamOrderID;
private void Page_Load(object sender, 
   System.EventArgs e)
{
   // Make sure an OrderID was sessioned off
   if (Session["OrderID"] != null)
   {
      // Set stored proc filter value to select only order data for this Order ID
      ParamOrderID.Value = 
         Session["OrderID"].ToString();
      // Set up new report based on Crystal RPT class created
      ReportDocument myReportDocument = new 
         ReportOrders();
      // Get data for order and populate dataset
      sqlDataAdapter1.Fill(dsReportOrderDetails); 
      myReportDocument.SetDataSource         
         (dsReportOrderDetails);
      CrystalReportOrders.ReportSource = 
         myReportDocument;
      // Put everything on the same page and create a 
      // printable version
      CrystalReportOrders.DisplayGroupTree = false;
      CrystalReportOrders.SeparatePages = false;
      CrystalReportOrders.DisplayToolbar = false;
   }
}