Binding by Report Object

Binding by a report object works slightly differently depending on if you have added the report to your project, or if you are referencing it externally. For a report that resides external to your application, you need to first specify an import of the CrystalDecisions.CrystalReports.Engine, which will allow you to create the object.

If this is not already present, we shall add it. In the Solution Explorer, right-click your project title and select Properties from the right-click menu to open the dialog shown in Figure 5-9.

Figure 5-9

Under the Common Properties folder, use the Imports option to add the CrystalDecisions. CrystalReports.Engine namespace to your project and click OK to return to your form.

With this namespace imported, we now need to create the report object as a ReportDocument in the form's Declarations section, as shown:

Dim myReport as New ReportDocument()

With our object now ready to be used, we can load the external report file by placing the following code under the Page_Init event:


myReport.Load("C:\Crystal.NET2003\Chapter05\sales_graph.rpt") CrystalReportViewerl.ReportSource = myReport

If the report you are using has actually been added to your project (as ours was earlier), a class was automatically generated for the report, so we could use the class instead to bind the report to the viewer (though the import and Public declaration remain the same):

InitializeComponent() myReport = New sales_graph()

CrystalReportViewerl.ReportSource = myReport

Or, if you wanted to eliminate the myReport variable:

CrystalReportViewerl.ReportSource = New sales_graph()

Which method you choose will depend on where the report is physically located and how you wish to access it.

Was this article helpful?

0 0

Post a comment