# VBForums CodeBank > CodeBank - Visual Basic .NET >  How to use Report Viewer with Visual Studio 2012 Express

## circuits2

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:
http://www.microsoft.com/en-us/downl....aspx?id=35576

After installing the Report Builder, you need to install the 2012 Report Viewer Runtime, which is also a free download on Microsofts website:
http://www.microsoft.com/en-us/downl....aspx?id=35747

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 11.0.0.0. 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:
http://msdn.microsoft.com/en-us/library/ff519552.aspx

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:


vb.net Code:
Imports Microsoft.Reporting.WinForms


This code assumes you know how to fill a datatable:


vb.net Code:
Me.BindingSource1.DataSource = MyDataTable
Dim rds As New ReportDataSource("DataSet1", Me.BindingSource1)
 Me.ReportViewer1.LocalReport.ReportPath = "C:\SalesReport1.rdlc"
Me.ReportViewer1.LocalReport.DataSources.Clear()
Me.ReportViewer1.LocalReport.DataSources.Add(rds)
Me.ReportViewer1.RefreshReport()

----------


## Static

Whats next? is there a way to print the report without a print preview etc?

and.. if i have built the report to have a parameter (@OrderID) how would i do that in vb?  (or is that just part of the data source....? should the report NOT have the parameter and then just do the parameter on the datatable?)

----------


## circuits2

> Whats next? is there a way to print the report without a print preview etc?


I think you need to slow down and follow the process, paying careful attention to each part. The ReportViewer control has a print button, as well as export buttons.





> and.. if i have built the report to have a parameter (@OrderID) how would i do that in vb?  (or is that just part of the data source....? should the report NOT have the parameter and then just do the parameter on the datatable?)


If you use my example, you only have to make sure the datatable you supply to the report has the same columns. I try not to use parameters when creating the report, that way they are not expected.

----------


## Static

ok then.. first things first.. my reportviewer control has NO controls? its doesnt show up on the form..it shows below (like if you add a timer)...?

----------


## circuits2

You must have missed the steps where you install the 2012 ReportViewer Runtime and add the new version of the control to your toolbox. The behavior you described is what you will get when using Version 10.0.0.0, which is what ships with Visual Studio 2012 Express. You have to remove that control from your toolbox and add Version 11.0.0.0, which is what the Runtime installs.

----------


## Static

you were correct.. although i had to just through hoops - both were installed (10,11) and it kept re-pointing to 10... took a few tries lol

thanks.


ok, next question. can you print right away without having to show anything?

Thanks!

----------


## circuits2

The print and export functions are provided by the ReportViewer. However, there has to be a report rdlc loaded in order to print, even if it has no data to show.

----------


## Static

AHA! Yes!! ok.. that is a pain!...

I have the Report Viewer working.. it opens, data loads, etc...

I know it has a print button etc, but i was hoping there was a way to have it autoprint?

i click a button.. the RV loads the report and shoots it right to the printer...


Nevermind! Got it!!

using this:
http://msdn.microsoft.com/en-us/library/ms252091.aspx
I added the class to my project, changed the data sources, tweaked the subs to allow me to pass in a value.. and BAM!!

Perfection!

Thanks!

----------


## ykiran77

Hi,

I have followed both the steps you had mentioned for downloading, but still that winforms.dll is not appearing when I browse that folder. Hence I reinstalled once again, but in vain. Could you please advice why I am not able to find it?

Regards,
Kiran





> 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:
> http://www.microsoft.com/en-us/downl....aspx?id=35576
> 
> ...

----------


## amberHancock

Hello,

I also followed the steps (twice) but I don't end up with this .dll file in the correct folder...

A

----------


## amberHancock

I should add - I don't even have a ReportBuilder folder in my Microsoft Visual Studio 11.0 folder.
I'm sure I didn't miss anything...

----------


## circuits2

> I should add - I don't even have a ReportBuilder folder in my Microsoft Visual Studio 11.0 folder.
> I'm sure I didn't miss anything...


The WinForms.dll is installed as part of the ReportViewer runtime, not the ReportBuilder. The install path may be slightly different on your system but a simple search will help you find it.

----------


## blmarik

I just don't know what to do anymore.  I have tried for over 6 hours to get this report viewer tool to show up in my toolbox.  I have followed your instructions meticulously but the Report Viewer folder will not show in my Visual Studio 11.0 folder.  I have searched for the dll file on my computer and cannot find it.  I have found the Report Builder file under my SQL Server program folder, but Report Viewer folder is just not anywhere.  What can I do to get this on my computer? or find it if it's already installed?

----------


## Goshx

Can someone write a good tutorial about using of Report Viewer related with programming? It is very hard to find any good resource about this control. I can't touch how to create a report using SQL statements.

----------


## jeff@databae.com

I installed both the Report Builder and the Report Viewer Runtime as indicated above.
Installation was successful.
However, the runtime dll does NOT install to the folder. 
I simply cannot find the Winforms.dll file. Even after searching the entire C: drive.
Anyone else have this problem? 
Anyone have the answer to this?
I'm using visual studio 2012 express and sql server 2012 express.
thank you!
Jeff

----------


## parentheticalclaws

Can anyone explain more about how to add the data source? I have data table, which I'm able to use with a data grid view control, but I cannot manage to link it to the report viewer. My report appears, with the correct columns, but with no data in it. Here is what I have:


```
Me.MerchantsTableAdapter1.FillBy(Me.TestDataSet1.Merchants)
Me.BindingSource1.DataSource = Me.MerchantsTableAdapter1
Dim rds As New ReportDataSource("DataSet1", Me.BindingSource1)
```

----------


## Quint

> I installed both the Report Builder and the Report Viewer Runtime as indicated above.
> Installation was successful.
> However, the runtime dll does NOT install to the folder. 
> I simply cannot find the Winforms.dll file. Even after searching the entire C: drive.
> Anyone else have this problem? 
> Anyone have the answer to this?
> I'm using visual studio 2012 express and sql server 2012 express.
> thank you!
> Jeff


I'm using Windows8 and vb2013 express and installed ReportBuilder and ReportViewer as indicated above. NOTE: The Microsoft.Reporting.WinForms.dll 11.0.0.0 was installed in a subdir of C:\windows\assembly\GAC_MSIL\Microsoft.ReportViewer.WinForms\11.0.0.0__….. 

Only thing remaining: how to get it working! This is what I did:

1. I built a report in ReportBuilder3.0. I used an Access database (Contacts.mdb). In the mdb there is a table Prive containing names, adresses, phone numbers etc. The Datasource in ReportBuilder I named ContactsDataSet (like the name VB2013 gave to my Datasource). The DataSet in ReportBuilder I named "DataSet1". The report resulting from ReportBuilder I named prive.rdl.

2. Next I renamed the rdl file to prive.rdlc

3. In my Contacts project (VB2013 Express) I added a button to my Form1 (btnPrint; the Click event is just Form2.Show).

4. I added Form2 to my project, drag and dropped ReportViewer to Form2. The control appeared on the Form2 surface and I added the following code to Form2: 

Imports Microsoft.Reporting.WinForms

Public Class Form2
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Me.ReportViewer1.RefreshReport()
    End Sub

    Private Sub ReportViewer1_Load(sender As Object, e As EventArgs) Handles ReportViewer1.Load
        Dim cn As New OleDb.OleDbConnection
        cn.ConnectionString = My.Settings.ContactsConnectionString
        cn.Open()

        Dim da As New OleDb.OleDbDataAdapter
        Dim sql As New OleDb.OleDbCommand("select * from prive order by naam", cn)
        Dim Prive As New DataTable

        da.SelectCommand = sql
        da.Fill(Prive)

        Dim bs As New BindingSource
        bs.DataSource = Prive

        Try
            Dim rds As New ReportDataSource("DataSet1", Prive)

            Me.ReportViewer1.LocalReport.ReportPath = "D:\prive.rdlc"
            Me.ReportViewer1.LocalReport.DataSources.Clear()
            Me.ReportViewer1.LocalReport.DataSources.Add(rds)
            Me.ReportViewer1.RefreshReport()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

        cn.Close()
    End Sub
End Class

4. When I click the print button on Form1 the report appears in Form2. It works!

5. Note: when you drag and drop the ReportViewer control the control should appear on the Form surface! If this does not happen try recreating your project from scratch; that's what I did when the ReportViewer control did not appear on my form. Possibly this has to do with the version of the ReportViewer control when you start your project; possibly changing versions in midstream is too confusing for VB ...

----------


## Quint

> I installed both the Report Builder and the Report Viewer Runtime as indicated above.
> Installation was successful.
> However, the runtime dll does NOT install to the folder. 
> I simply cannot find the Winforms.dll file. Even after searching the entire C: drive.
> Anyone else have this problem? 
> Anyone have the answer to this?
> I'm using visual studio 2012 express and sql server 2012 express.
> thank you!
> Jeff


On Windows 8 I found the Microsoft.Reporting.WinForms.dll in a subdir of C:\windows\assembly\GAC_MSIL\Microsoft.ReportViewer.WinForms\11.0.0.0__..

----------

