Binding to an Untyped Report

When working with Crystal Reports .NET, you can add individual report files to your project and use and reference them to view reports from your application. Taking this a step further, you could also use these reports as components, which is where we start looking at typing.

When integrating reports into an application, we can use either strongly typed reports or untyped reports. If you have been working with Visual Studio .NET for any length of time, you have probably heard of strongly typed objects. A strongly typed object is predefined with a number of attributes that are specific to that object, giving programmers more structure and a rigorous set of rules to follow, whereas an untyped report does not have this structure or rules applied to it, making it more difficult to work with.

Within the frame of reference of Crystal Reports .NET, a strongly typed report can be any report that has been added to your project. When you add a report to a project, you will notice that in addition to the report, another file (with a .vb extension) is also added, as shown in Figure 5-10.

This file is hidden until you select Show All Files from the Solution Explorer.

This additional file is the report source file and contains a report class specific to each report, called ReportDocument, which is derived from the ReportClass class and is created automatically for you.

An example of an untyped report would be a report that is stored externally to your project. For instance, you could view a report by setting an external reference (as in our first example, where we set the ReportSource property in the (DataBindings) to "C:\Crystal.NET2003\Chapter05\ web_viewer_basic\sales_graph.rpt".

We'll just have a brief look at how we do this. Create a virtual directory called web_viewer_untyped pointing at C:\Crystal.NET2003\Chapter05\web_viewer_untyped (if this is where you have downloaded the source code to), or alternatively, build it from scratch.

Solution Explorer - web_Yiewer_bask rejjglfi m

Solution 'web_viewer_baslc' (1 project)


References J bin

J dynamlcjnnages

{07AD4CAD-0F4F-483ti-A06B-57AC4D9E774E}-.rpt 'Ei Assemblylnfo.yb Global.asax

Web.conflg "I WebForml,aspx

Figure 5-10

To add a report component to your application, switch to the Layout view of your form and look in the toolbox under Components. In this section, you should see a component labeled ReportDocument. Drag this component onto your form, which will open the dialog shown in Figure 5-11.

Figure 5-11

It is in this dialog that you set whether your ReportDocument component is typed or untyped. If you select Untyped ReportDocument, you are not really accomplishing much new here. Drag a new CrystalReportViewer onto the Web Form, and then load a report into ReportDocumentl and bind the component to the viewer.


Dim ReportDocumentl As New ReportDocument()

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

Was this article helpful?

0 0

Post a comment