This is part 2 of creating a crystal report. In this article we have discussed about the Push model and Pull model of the crystal report viewer.
Before reading we suggested to read
Creating Your First Crystal Report - Part 1
Push Model Report using Crystal report viewer
-
Open the default.aspx page.
-
From the toolbox select the CrystalReportViewer control in the Reporting section. (I am using
-
Visual Studio 2008 for this example).
-
The Crystal Report Viewer control will now be displayed in your default.aspx form.

-
Right Click on the Crystal Report Viewer control in the web form and select the properties so that the property window will be displayed.
-
Select the ReportSourceId. Then click “New Report Source” from the list

-
The next display will be the create Report Source window. Select the “Specify a Crystal report for the CrystalReportSource Control” dropdown. The report that created using Pull model or Push model will be in the drop down.
-
Select PullModelReport.rpt which is report created using pull model which is explained in Pull model Crystal reports.

-
Click Ok.
-
Now run the application.
-
The application will prompt you for the user name and password to connect to the database. In a later part of the tutorial, we will see how to prevent the report from asking the user name and password. So don’t worry about this section now.
-
After giving the username and password, then click the Log on button. The report will now be displayed.

Now we have successfully listed the Employee information from the Northwind database
Push Model Crystal Reports
In order to use the push model, complete the steps in Creating your first Crystal report part- 1 and open the Page_Load event of the default.aspx page.
Import the following name spaces:
Imports System.Data.SqlClient
Imports System.Data
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.CrystalReports
Imports CrystalDecisions.Shared
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim con As New SqlConnection("Database=Northwind;uid=username;password=password;server=yourservername")
con.Open()
Dim strQuery As String = String.Empty
strQuery = "select * from Employees where Country='USA'"
Dim cmd As New SqlCommand(strQuery, con)
Dim da As New SqlDataAdapter(cmd)
Dim dt As New DataTable
da.Fill(dt)
Dim strPath As String = Server.MapPath("PullModelReport.rpt")
Dim rd As New ReportDocument()
rd.Load(strPath)
rd.SetDataSource(dt)
CrystalReportViewer1.ReportSource = rd
End Sub
In the above example, the data table object has been created using the SQL Server connection. Additionally, the ReportDocument object has been created, which is the top level of the Crystal Reports object model. The ReportDocument contains all the properties and methods needed to interact with and customize a report. We can use the Load() method to open the report.
To use the ReportDocument, you must first add a reference of CrystalDecisions.CrystalReports.Engine Namespace, which is found in the CrystalDecisions.CrystalReports.Engine.dll. This reference will automatically be added if you have inserted a report into your application.
After load() method, set the ReportSource of the CrystalReportViewer control as ReportDocument. When you run the application, the report will display the records from the employees table where the country name is USA. This type is called a Push Model Report.