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
- Launch Visual Studio.
- From the File menu, select New, and then click Project.
- In the New Project dialog box, select a language folder for C# or Visual Basic from the Project Types list.
- From the Templates list, click Windows Application.
- In the Name field, replace the default project name with the name of your project.
- Click OK.
To create and bind a Crystal report to the Windows project
Open the Windows Form in Design view.
From the Toolbox, open the Crystal Reports node to locate the CrystalReportViewer control.
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.
If the Smart Tasks panel is not open, click the arrow toggle on the upper-right corner of the CrystalReportViewer control.
From the CrystalReportViewer Tasks panel, click Create a new Crystal Report….
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.
In the Create New Crystal Report Document panel of the Crystal Reports Gallery dialog box, select Using a Report Wizard.
In the Choose an Expert panel, select Standard, and then click OK.
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.
- 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.
Expand the Tables node, double-click the Employee table to move the table to the Selected Tables panel, and then click Next.
Expand the Employee table, then CTRL-click Employee ID, Last Name, First Name, and Salary.
Click the > symbol to move these fields into the Fields to Display panel, then click Next.
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
- 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.
From the Build menu, select Build Solution.
If you have any build errors, go ahead and fix them now.
From the Debug menu, click Start.
The Employees report is displayed successfully with the dummy data.
- Return to Visual Studio and click Stop to exit out of debug mode.
Continue to Setting the ClickOnce Deployment Properties.