Crystal Reports from XML File

In this section, we will explore the process of creating Crystal Reports using an XML file instead of a traditional database as the data source. The methodology for creating Crystal Reports from an XML file is quite similar to that of creating reports from a database. The key distinction lies in selecting the data source as your XML file.

To begin, we will create an XML file named "Product," which mirrors the structure of the Product table found in the sample Database Structure. This XML file will serve as the data source for our Crystal Reports.

Download Product.XML

vb.net_crystal_report_xml_1.GIF

Before proceeding with this section, it is assumed that you have a basic understanding of Crystal Reports creation. However, if you are new to Crystal Reports or require a refresher, I recommend referring to the step by step Crystal Report tutorial provided earlier in the tutorials. This tutorial offers a comprehensive guide on creating Crystal Reports, ensuring you have the necessary knowledge to proceed with this section.

The key change in this section lies in the selection of data for your Crystal Report. Instead of choosing a traditional database as the data source, you will opt for a different approach. When selecting the data for your Crystal Report, you will navigate to the "Create New Connection" option and choose "Database Files." From there, you will select the XML file you wish to use for generating the Crystal Reports, specifically the "Product.xml" file in this case.

vb.net_crystal_report_xml_2.GIF

Select all the fields from Product and click finish button

Now the designer part is over . Next step is to select the default form(Form1.vb) and add a Button and Crystal Reports Viewer to the Form.

Put the following vb.net source code in your form and run the program .

Full Source VB.NET
Imports CrystalDecisions.CrystalReports.Engine Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click Dim cryRpt As New ReportDocument cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt") CrystalReportViewer1.ReportSource = cryRpt CrystalReportViewer1.Refresh() End Sub End Class

cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt")

The Crystal Report is in your project location, there you can see CrystalReport1.rpt . So give the full path name of report here.