نحوه ایجاد گزارش با کریستال ریپورت
This article will help you to create reports using Crystal Reports. Here I am giving step by step idea to create reports in an easy way. Here I have covered Crystal reports features such as Grouping, Graph, Cross-Tap, Sub report, etc.
I am going to explain the below 5 features.
- Simple Crystal Report
- Group in Crystal Report
- Graph in Crystal Report
- Cross-Tab in Crystal Report
- Sub report in Crystal Report
Let’s start by creating a new ASP.Net Web Site. Figure 1 shows the initial web site creation screen.
By clicking OK button you can see the project created in solution explorer. Now let’s start with Crystal Report.
Before that, I am going to show my table structure and data’s in table. So this will help you to understand the steps easily. Figure 2 will show the table structure and Figure 3 will show the data’s in table.
But in attached project I am getting data’s from xml file. I have saved all the data’s from table to xml. So you can easily use the attached project. Next Dataset (xsd file) creation.
There are so many ways to pass the data to Crystal Report. Here I am using Dataset (xsd file) to bind Crystal Report. In my point of view, this is the best way to bind. So, next step is Dataset (xsd file) Creation.
Go to Solution Explorer -> Right click on the Project -> Add New Item. Figure 4 Shows the Dataset creation.
Once you click of Add button, it will ask one confirmation message. Just click yes. Now you can see the dsTestCrystal.xsd dataset file opened in visual studio. Here you need to create one Data Table with the all columns names need to shown in Crystal Report. To Create Data Table see the below Figure 5.
Now you can see Data Table created in the Dataset. Next we need to add the columns names need to shown in Crystal Report. Please note that, this Data Table column names and data types should be same as your table in database. If you are getting any data type property mismatching error just think that this is the problem. To Create Column names see the below Figure 6.
Add the all columns one by one and set the correct data type. Here by default data type is string. If any columns having different data type we need to change manually. In this project I am using ‘Marks’ column data type as int. So to change the data type see the below Figure 7.
Dataset (dsTestCrystal.xsd) creation has been done. Now we need to design Crystal Report.
1. Simple Crystal Report
Go to Solution Explorer -> Right click on the Project -> Add New Item. Figure 8 Shows the Dataset creation.
On click of Add button you will get Crystal Report Gallery window. In that select Using the Report Wizard check box and Click OK button. Now you will get the below Figure 9.
Now expand the ADO.NET Datasets folder. There you can see the Dataset (dsTestCrystal) we created. Under dsTestCrystal you can see the Data Table we created. So select this Data Table and click the arrow button to move to the Selected Tables list box as shown in below Figure 10.
Just click the Finish button. Now you can see the Crystal Report opened in Visual studio. In your left side you can see Field Explorer. In you cannot see there just go to menu Crystal Reports -> Field Explorer. Field Explorer View is shown in below Figure 11.
Now you can drag and drop the columns from Field Explorer to Details Section in Crystal Report. You can see the final view of the Crystal Report in the next Figure 12.
Crystal Report design also done. Now we need to pass the data’s to the Dataset (dsTestCrystal) and we need to set this Dataset to Crystal Report.
Now just create one aspx page. Add the below code in .aspx page.
Then write the below code in .aspx.vb page to generate Crystal report.
Now run your page and the datas generated in Crystal Report.
2. Crystal Report using grouping
Here I am going to explain only the Crystal Report design. Remaining things you can refer from previous one.
I am going to use the Group like Class -> Name -> Subect & Marks. Here Class and Name is Group. Subject and Marks will come in detail section. To create Group see the below Figure 13 & 14.
Class is the main group. So first we need to move Class field to Group By list box by clicking the arrow button. Then we need to move the Stud_Name field. See the below Figre 15.
Now click OK button and see the difference in Crystal Report. There you can see two Header & Footer added and two fields Group #1 Name, Group #2 Name. Group #1 Name is Class and Group #2 Name is Stud_name. See the below Figre 16.
Now you can drag and drop the columns from Field Explorer to Details Section in Crystal Report. You can see the final view of the Crystal Report in the next Figure 17.
Now I am going to add sum of marks for the student. In Stud_Name GroupFooterSection we need to add this sum. See the below Figure 18.
On click of Summary you will get the below Figure 19.
We need the sum of Marks column. So select Marks field from first combo box. Then select Sum from the second combo box. Finally we need sum of marks for each student. So we need to select Stud_Name group from third combo box. Then click OK button. Now you can see the sum field added in Stus_Name footer section. See the Final view of Crystal Report in the below Figure 20.
3. Chart in Crystal Report
Here also I am going to explain only the Chart design. Remaining steps same as first one.
I am going to show the students total marks in student wise. X-axis is Student names and Y-axis is Total Marks. Lets start the creation of chart. See the below Figure 21.
Once you click the Chart you will get the below Figure 22. Here you can see number of chart formats. So yo can select any one from her