Share via


Creating and Binding a Report

In this section, you create a Crystal report that binds to a CrystalReportViewer control.

To set up a Windows project in Crystal Reports for Visual Studio

  1. Launch Visual Studio.
  2. From the File menu, select New, and then click Project.
  3. In the New Project dialog box, select a language folder for C# or Visual Basic from the Project Types list.
  4. From the Templates list, click Windows Application.
  5. In the Name field, replace the default project name with the name of your project.
  6. Click OK.

To create and bind a Crystal report to the Windows project

  1. Open the Windows Form in Design view.

  2. From the Toolbox, open the Crystal Reports node to locate the CrystalReportViewer control.

  3. Drag and drop the CrystalReportViewer control onto the form.

The CrystalReportViewer control supplies a new GUI feature known as Smart Tasks that is titled "CrystalReportViewer Tasks". The Smart Task panel enables you to implement commonly used settings, such as report binding.
  1. If the Smart Tasks panel is not open, click the arrow toggle on the upper-right corner of the CrystalReportViewer control.

  2. From the CrystalReportViewer Tasks panel, click Create a new Crystal Report….

  3. In the Create a New Crystal Report dialog box, type "Employees.rpt", and then click OK.

The Crystal report is created and added to the project. A report class is generated with the same name as the report.
  1. In the Create New Crystal Report Document panel of the Crystal Reports Gallery dialog box, select Using a Report Wizard.

  2. In the Choose an Expert panel, select Standard, and then click OK.

  3. In the Available Data Sources panel of the Standard Report Creation Wizard window, do the following:

1.  Expand the Create New Connection folder.
2.  Expand the ODBC (RDO) folder.
  1. In the ODBC (RDO) window, select the correct ODBC DSN entry for your version of Crystal Reports as explained in ODBC DSN Entry for Xtreme Sample Database, and then click Finish.
The ODBC (RDO) folder expands and shows the Xtreme Sample Database.
  1. Expand the Tables node, double-click the Employee table to move the table to the Selected Tables panel, and then click Next.

  2. Expand the Employee table, then CTRL-click Employee ID, Last Name, First Name, and Salary.

  3. Click the > symbol to move these fields into the Fields to Display panel, then click Next.

  4. In the Available Fields panel, under Report Fields, double-click Employee.Employee ID to move the field into the Group By panel, and then click Finish.

At the bottom of the report designer, click Main Report Preview to preview the report with dummy data.

The Employees report is created and loaded into the main window of Visual Studio.

To test the loading of the CustomersByCity report

  1. Return to the Windows Form in Design view.
The Employees report is displayed as "Employees1" in the Component tray at the bottom of the window. The CrystalReportViewer control displays the Employees report.
  1. From the Build menu, select Build Solution.

  2. If you have any build errors, go ahead and fix them now.

  3. From the Debug menu, click Start.

The Employees report is displayed successfully with the dummy data.
  1. Return to Visual Studio and click Stop to exit out of debug mode.

Continue to Setting the ClickOnce Deployment Properties.