The paid versions of Visual Studio include an add-in called Report Builder which lets you create reports from a dataset in design mode. Using Report Builder results in the creation of a file similar to Report1.rdlc, which is a Client Definition file. You then use the ReportViewer control from the toolbox to show this report in one of your forms.
In Visual Studio Express, you do not have the Report Builder utility, nor do you immediately have the ReportViewer in your toolbox. However, with a little setup time you can use Report Builder just as easily.
Report Builder is actually a component of SQL Server. If you are using SQL Server 2012 Express, make sure you have selected all of the reporting features that are offered during installation, or you can go back and add them to your instance by running the same setup file again.
SQL Server Express does not include Report Builder, but it is a free download on Microsoft’s website:
After installing the Report Builder, you need to install the 2012 Report Viewer Runtime, which is also a free download on Microsoft’s website:
Once both are installed, open Visual Studio 2012 Express and go to Tools > Choose Toolbox Items.
If you scroll through the list on the .NET tab you will find two ReportViewer controls, one for WebForms and the other for WinForms. Both of those are version 10.0.0.0, which ships with VS 2012. We actually want the new version that we installed, which is version 184.108.40.206. You can find it by clicking on the browse button.
Navigate to the ReportViewer Runtime that you installed and select Microsoft.ReportViewer.WinForms.dll.
Now you will find the Report Viewer control in your toolbox.
Now, I’m not going to go through the entire process of showing you how to use Report Builder. You can find a great example here:
What you should know, is that Report Builder will create a file like Report1.rdl. Notice that this file does not end with .rdlc like the one that is created using the Report Builder add-in for Visual Studio!
Simply add the “c” to the end of the extension and you can now access the file using the Report Viewer control.
A few hints. When you supply your report with a datatable in code, it will need to have the same name as the dataset you created in Report Builder.
Here is an example of filling a datatable and then showing a report:
- Imports Microsoft.Reporting.WinForms
This code assumes you know how to fill a datatable:
- Me.BindingSource1.DataSource = MyDataTable
- Dim rds As New ReportDataSource("DataSet1", Me.BindingSource1)
- Me.ReportViewer1.LocalReport.ReportPath = "C:\SalesReport1.rdlc"