ARTICLE

Different methods of loading Crystal Report in Crystal Report Viewer

Posted by Sarath K.S. Articles | Crystal Reports in VB.NET October 27, 2006
This article explains different methods of loading Crystal Report in the Windows Forms from VB.NET.
 
Reader Level:

This article explains different methods of loading Crystal Report in the Windows Forms from VB.NET.

1. By Report Name - This method of loading a report simply specifies the  location of the report and sets it as the reportsource for the viewer.

Dim filePath As String
filePath = Application.StartupPath + "\ReportName.rpt"
CrystalReportViewer1.ReportSource = filePath

2. By Report Object - This method of loading a report creates a new instance of the ReportDocument object from the CrystalDecisions.CrystalReports.Engine namespace and loads a report into the object by specifying the physical path to the report.

Dim filePath As String
filePath = Application.StartupPath + "\ReportName.rpt"
'Create a new instance of the reportdocument object and load the report
Dim objReportDocument As New CrystalDecisions.CrystalReports.Engine.ReportDocument()
objReportDocument.Load(filePath)
'Bind the report to the viewer
CrystalReportViewer1.ReportSource = objReportDocument

3. By Untyped Report Component - This method of loading a report uses the ReportDocument component from the Components tab of the ToolBox.  When this component is added to the form, a dialogue box appears and prompts the Developer as to which type of Component to add to the form.  The options selected were 'Untyped ReportDocument' and a component called ReportDocument1 was added to the form.  This component acts as a proxy to the ReportDocument class.

Dim filePath As String
filePath = Application.StartupPath + "\ReportName.rpt"
Dim reportdocument1 As New CrystalDecisions.CrystalReports.Engine.ReportDocument()
'load the report into the report document component and set the component as the reportsource for the viewer
reportdocument1.Load(filePath)
CrystalReportViewer1.ReportSource = reportdocument1

4. By Report Object - This scenario uses a report object that has been added to the current Project.  When a report is added to a project, a class file is generated for the report making the report a strongly-typed object, in this case 'ReportName.rpt'

'Bind a new instance of the strongly-typed report object to the viewer
CrystalReportViewer1.ReportSource = New ReportName()

5. By Strongly-Typed Report Component - This method of loading a report uses the ReportDocument component from the Components tab of the ToolBox.  When this component is added to the form, a dialogue box appears and prompts the Developer as to which type of Component to add to the form.  The 'Name' option selected was the strongly-typed report that was added to the project (SolutionName.ReportName).  The option to generate a Cached Strongly-Typed Report was deselected and a report component called 'ReportName1' was created and added to the form.

' Friend WithEvents ReportName1 As SolutionName.ReportName1 -This piece of code will be there under 'Windows forms designer generated code section.
'Bind the strongly typed report component to the viewer
CrystalReportViewer1.ReportSource = ReportName1

Login to add your contents and source code to this article
share this article :
post comment
 

how to add crystalreportviewer in vs 2010

Posted by piyush Feb 16, 2011

Hi,

I want to show crystal report paramter window as it in asp.net web page.

How can i do this. please do the needful.

Posted by sapana patil Mar 27, 2010

plz send another way to load report becauase this method is not work .

Posted by rakeshmahur mahur Oct 23, 2009

hi will you kindly suggest me the code how to display asingle record's(particular record) crystal report from a db that contains number  of record

Posted by abdul wahab Sep 05, 2009

Dear Can you help me on barcode software development. I m new on vb.net want to develop a barcode software please if possible help me. Thnaks

Posted by Jewel Ahmed Feb 16, 2008
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Become a Sponsor