REPORTING WITH REPORTING SERVICES

Oh ok, so i don’t even need to worry downloading crystal reports for my Visual Studio 2010. Reporting services has been there for a while but did not bother to consider because I have been comfortable with crystal reports, but working on my first project with VS 2010 I had to, because was not seeing crystal reports and had to go through some processes to integrate. So i decided to give Reporting services a try and guys it is very cooooool. Are you a beginner in Reporting Services in Visual Studio, then this will offer you a great help.

Lets go through how to create a report using reporting services and dataset as the data source.

It is assumed you are working with a project with a dataset.

1. Right click to add a new item to your project. On the Reporting tab, choose “Report Wizard” and enter the name of your report in the “name” field provided at the bottom of the “add new item” dialog box. Click on the “Add’ button to proceed.

image

2. In this stage , you choose the data source of your report. You start by entering the name of your Dataset. Take note of the name you enter as you will use it in your code. Select the data source ( the dataset of your project) and then select the table you want to display in your report. Click next to go to the next stage.

image

3.Here, you choose the fields to display on your reports and how to group your records, either by rows or columns. Drag the fields you want to display in the “Values” area. In case you want group your records by rows or columns, drag that field to the “row groups” or “column groups “ respectively. Functions like sum,average, etc can be applied to  fields in the “values’ area. Click next to go the next tab

image 

4. In this stage you choose the layout of your report. Select your layout and click on the next button.

image

5. Select your report style and click on the finish button.

image

 

Your report is then displayed with the selected fields. You can then drag the table to a position of your choice on the report form. You can also insert text and image onto your report as it is done in crystal report.

image

After creating the reports you then have to integrate it into your forms. First you need to add a report viewer. You do this by creating a new form and dragging the report viewer onto it as shown below.

image

After this, you write some small codes to view your report.  First you have to make sure the data table is filled programmatically. Let say at form load event we want to display the report. We start by declaring a procedure that can that accepts the dataset name, report name and the datasource.

   1: public void fillReport(String dataset, String reportname, DataTable loadData)

   2:        {

   3:            this.reportViewer1.ProcessingMode = ProcessingMode.Local;

   4:            //choosing the report source

   5:            this.reportViewer1.LocalReport.ReportPath = Application.StartupPath + "/" + reportname + ".rdlc";

   6:            //add the datasource to the report

   7:            this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource(dataset, loadData));

   8:            this.reportViewer1.RefreshReport();

   9:  

  10:        }

so on form load we fill the data table and call the method above to fill the show the report.

“fillReport("DataSet1", "purchaseSearch", this.dataSet1.land”

Note that the dataset name should be the same as shown in the created report.

Enjoy…