Reader Level:

Crystal Report Viewer in WPF: Part 1

By Nipun Tomar on Dec 28, 2011
Reports has been the reporting tool of choice included with Visual Studio and here you learn how to add Crystal report in WPF application.

In my previous article I have discussed about the Report Viewer Control in WPF. Today, I am here to describe how to add Crystal report in WPF application, as we already know that "Crystal reports a long-time Visual Studio add-in staple, but are not included with VS 2010 this time". Basically, Crystal Reports has been the reporting tool of choice included with Visual Studio. While the Crystal Report engine is not included with VS 2010, there is still a Crystal Report template included that stubs our project as a Crystal Reports project. We can then obtain the new Crystal Report for VS 2010 report by downloading it free of charge from the SAP website. Currently that link is here.

This download includes a new WPF viewer for Windows Forms, which has some nifty new features.

So, let's begin with Crystal Reports:

  1. After completing the installation, Open your visual studio and start with a WPF Application and rename your application as "WpfCrystalReport".


  2. From the Solution Explorer, right-click on your project, and point to Add, and select New Item.


  3. In the Add New Item dialog box, select "ADO.NET Entity Data Model" from Data templates, and click Add. Which will open the Entity Data Model Wizard like this:



  4. Select the "Generate from database" option and click the Next button.
  5. Now you have to choose your data connection so, click on "New Connection".


  6. In the Server name box, type the server name that hosts your database, as I have used the localhost and for this I have to log on to my server and in "Select or enter a database" name, select the database which you are going to use, and test your connection before clicking OK.


  7. Now, Select the option to include the sensitive information in the connection string and check the box to save the connection string in the App.Config file. Click on Next twice and the page "Choose your Database Objects" will be opened.


  8. In the Choose Your Database Objects page, expand the Tables node, select the checkbox for the table for which you want to create a report, and click Finish.


  9. The Model1.edmx model will appear in the Visual Studio designer.

  10. After finishing the work for model let's start with Crystal Report:

    Note: This report will be bound to the data by using the LINQ query. To do this we need to create XSD file that contains the fields that are returned by the LINQ query. This file is used by the Crystal Reports designer to allow us to design the report.

  11. Again from the solution Explorer right-click your project, point to Add, and select New Item.


  12. From the Add New Item dialog box , select the Data node from the list of templates and then select the DataSet template.


  13. Now, right click on the design surface and Select Add >> DataTable. So that you will find a data table on your design surface:



  14. Again right click on the data table and select Add >> Column. Give a name to a column as CustomerName.


    reportview15.gif   reportview16.gif

  15. And create the Columns for Address, EmailId, and PassportNumber same as done for CustomerName. Also Save this file.


Remaining steps will be continues in second part of this article. Happy Learning...

Nipun Tomar
Nipun Tomar

Nipun Tomar is competent and experienced project leader & architect with 10 years of experience in managing multi-disciplinary teams of varying sizes and complex programs of work. Has the ability to build strong relation... Read more



Spire.Doc - Free .NET Word API
Use Spire.Doc to create, read, write, print, and convert word documents to OpenXML, RTF, TXT, XPS, EPUB, EMF, HTML, Image and PDF.

Trending up