Click here to Skip to main content
15,893,923 members
Articles / Desktop Programming / Windows Forms

Reporting XML data using Crystal Reports

Rate me:
Please Sign up or sign in to vote.
4.04/5 (14 votes)
22 Oct 2007CPOL9 min read 137.4K   49  
This article will show you how to report XML data with Crystal Reports and a Windows Forms client.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace XMLCRReport
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            DataSet dsReport = new dsCDCatalog();

            // create temp dataset to read xml information
            DataSet dsTempReport = new DataSet();

            try
            {
                // using ReadXml method of DataSet read XML data from books.xml file
                dsTempReport.ReadXml(@"C:\articles\XmlCrystalReport\cd_catalog.xml");

                // copy XML data from temp dataset to our typed data set
                dsReport.Tables[0].Merge(dsTempReport.Tables[0]);

                //prepare report for preview
                rptXMLData rptXMLReport = new rptXMLData();
                rptXMLReport.SetDataSource(dsReport.Tables[0]);
                crystalReportViewer1.DisplayGroupTree = false;
                crystalReportViewer1.ReportSource = rptXMLReport;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect FeatherSoft Inc.
Canada Canada
Asif Sayed has over twenty + years experience in software development and business process architecture. He has a consulting firm in Toronto, Canada. His firm provides IT solutions to all sizes of industries. He also teaches .NET technologies at Centennial College in Scarborough, Ontario. Recently he has become member of team as a subject matter experts with Microsoft's Learning Division. He has a book published by Apress with the Title "Client-Side Reporting with Visual Studio in C#".

My blog: http://www.dotnetsme.com
My Website: http://www.feathersoft.ca

Comments and Discussions