Free - Reporting XML data using Crystal Reports
Reporting on data sources such as: MS Access, SQL Server and Oracle, is common with Crystal Reports (CR). How about XML as data source? Well, sure, you might be wondering how to do that? Is it even possible? Well, with help of this article I’ll show you how to use the XML data source and report on it using CR.
This article will show you how to report
on XML data with Crystal Reports and Windows Forms client.
Figure: 1 – Example in run-time mode
I assume the reader has the basic
understanding of the Visual Studio (VS) 2005 IDE and Crystal Reports. You
should also comfortable writing code with C#. Basic understanding of XML schema
and ADO.NET is desirable.
What is XML Data?
Before we see the demo, let's get to know
what XML data is! If I can put in simple words, then XML stands for Extensible
Markup Language. It is an initiative by W3C to allow the exchange of
information which is easy to understand by both humans and computers. The
information stored in XML format can work on cross platform scenarios. For
example if you have information in XML format, it is easy to share between the
UNIX and the Windows platform. The data inside XML file is presented with user
define tags. Following is the partial listing from the sample XML file which I
am using with this demo:
<CD>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
</CD>
As you can see, each <CD> tag is
equivalent to a row with information related to CD. Further, each column is
uniquely identified as a tag. You can learn more on XML from here: http://www.w3schools.com/xml/xml_whatis.asp.
All right, let's start with our demo and see how easy it is to report on XML
data with CR and Windows Forms.
Step 1: Let's create a Windows Application Project
If VS 2005 IDE is not already started, then
you can launch the IDE by clicking on Windows Start button->All
programs->Microsoft Visual Studio 2005->click on
the icon Microsoft Visual Studio 2005. You may have other ways to lunch
the IDE, such as clicking it on your desktop and so on.
Please do the following steps to create a
Windows Application Project:
- Click on menu File->New->Project… or you can press the hot key Ctrl + Shift + N (please see
Figure 2)
- From New Project dialog box select Visual
C#->Windows
- From Templates select Windows
Application
- Please give a name to the application; I've
called the project as "XMLCRReport". You may choose a different location for
storing the application files as per your preference. Please see Figure 2 for
illustration of the naming process.
- Click on OK button to finish the process. VS
2005 will create a new project and add Form1 to it as default.
Figure: 2 – Process to create New Windows Application Project
Tip: You can always access the menu View->Toolbox or press Ctrl + Alt + X, to make Toolbox window visible. To get the maximum space on designer surface, you may like to use Auto Hide
feature of Toolboxes.
Let's set properties of Form1 according to
Table 1. In case if property
toolbox is not visible in IDE, you may hit F4 key to make it visible.
Pease make sure to select Form1 by before applying changes to properties using
property toolbox.
Table 1. Properties of Form1
Property |
Value |
Text |
Reporting XML data using Crystal Reports |
Size |
700,300 |
Step 2: Let's add CrystalReportViewer to Form1
Crystal Report Viewer (CRV) control is
needed for us to show the report to the user. Report Viewer gives life to your
reports. Not only it previews the output, but it also allows you to generate
the information in the various popular formats (PDF, Excel, etc.). You can also
take a hard copy print of the report while you are viewing the output.
You can add CRV to Form1 as follows:
- Make sure Form1 is currently open in designer.
- Drag ToolBox ->CrystalReports->CrystalReportViewer and drop it on the Form1. This step will create a new instance of CRV with the
name crystalReportViewer1. You can name it anything; I'll stick with the
default.
After the step 1 and step 2, your project
should look similar to Figure 3.
Figure: 3 – Form1 designer surface after adding CRV
I started to code in 1990 using C and GW basic, then moved to 4GL world with DBIII, Clipper and FoxPro etc. and continued till I found and hooked to MS goody bag Visual Basic. For last four years, I am working extensively on .NET technologies and scripting both VB.NET and C#. My ideal choice of database is SQL Server; however, I do interact with Oracle when required. I have worked on all sort of Business applications, but my ideal project would be anything which has some Financial part associated with it, I wish I can put a Balance-sheet report in all the project I do… I also teach .NET related technologies as part-time faculty with local community college and try to help share my knowledge with others.
See All Postings From Asif Sayed >>
Reviews
Balance sheet
hi
can u pls. guide me how to print a balance sheet in crystal reports ? i mean T Format where the data from 1 table i.e. Libilities would be coming on 1 side while the Assets table would be coming on the other side. i am really confused as to how i can do this. i would love to have an solution to this.
thankx in advance.
kuldev
You must me logged in to write a review.