Crystal Report Viewer in WPF: Part 1
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. 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:
- After completing the installation, Open your visual studio and start with a WPF Application and rename your application as "WpfCrystalReport".
- From the Solution Explorer, right-click on your project, and point to Add, and select New Item.
- 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:
- Select the "Generate from database" option and click the Next button.
- Now you have to choose your data connection so, click on "New Connection".
- 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.
- 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.
- 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.
- The Model1.edmx model will appear in the Visual Studio designer.
- 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.
- Again from the solution Explorer right-click your project, point to Add, and select New Item.
- From the Add New Item dialog box , select the Data node from the list of templates and then select the DataSet template.
- Now, right click on the design surface and Select Add >> DataTable. So that you will find a data table on your design surface:
- Again right click on the data table and select Add >> Column. Give a name to a column as CustomerName.
- 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...