Crystal Report Viewer in WPF: Part 1



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. http://www.businessobjects.com/jump/xi/crvs2010/us2_default.asp

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".

    reportview1.gif

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

    reportview2.gif

  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:

    reportview3.gif

    reportview4.gif

  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".

    reportview5.gif

  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.

    reportview6.gif

  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.

    reportview7.gif

  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.

    reportview8.gif

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

    reportview9.gif
  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.

    reportview10.gif

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

    reportview11.gif

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

    reportview12.gif

    reportview13.gif

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

    reportview14.gif

    reportview15.gif   reportview16.gif

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

    reportview17.gif

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