How to use Report Viewer with Visual Studio 2012 Express-VBForums
Results 1 to 18 of 18

Thread: How to use Report Viewer with Visual Studio 2012 Express

  1. #1

    Thread Starter
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,025

    How to use Report Viewer with Visual Studio 2012 Express

    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.

    Name:  viewer1.png
Views: 50440
Size:  19.7 KB


    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.

    Name:  viewer2.png
Views: 50504
Size:  61.8 KB


    Navigate to the ReportViewer Runtime that you installed and select Microsoft.ReportViewer.WinForms.dll.

    Name:  viewer3.png
Views: 50607
Size:  113.1 KB


    Now you will find the Report Viewer control in your toolbox.

    Name:  viewer4.png
Views: 49891
Size:  10.9 KB


    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:
    1. Imports Microsoft.Reporting.WinForms


    This code assumes you know how to fill a datatable:

    vb.net Code:
    1. Me.BindingSource1.DataSource = MyDataTable
    2. Dim rds As New ReportDataSource("DataSet1", Me.BindingSource1)
    3.  
    4. Me.ReportViewer1.LocalReport.ReportPath = "C:\SalesReport1.rdlc"
    5. Me.ReportViewer1.LocalReport.DataSources.Clear()
    6. Me.ReportViewer1.LocalReport.DataSources.Add(rds)
    7. Me.ReportViewer1.RefreshReport()
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

  2. #2
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,370

    Re: How to use Report Viewer with Visual Studio 2012 Express

    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?)
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3

    Thread Starter
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,025

    Re: How to use Report Viewer with Visual Studio 2012 Express

    Quote Originally Posted by Static View Post
    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.


    Quote Originally Posted by Static View Post
    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.
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

  4. #4
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,370

    Re: How to use Report Viewer with Visual Studio 2012 Express

    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)...?
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  5. #5

    Thread Starter
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,025

    Re: How to use Report Viewer with Visual Studio 2012 Express

    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.
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

  6. #6
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,370

    Re: How to use Report Viewer with Visual Studio 2012 Express

    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!
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  7. #7

    Thread Starter
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,025

    Re: How to use Report Viewer with Visual Studio 2012 Express

    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.
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

  8. #8
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,370

    Re: How to use Report Viewer with Visual Studio 2012 Express

    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!
    Last edited by Static; Apr 15th, 2013 at 08:47 AM.
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  9. #9
    New Member
    Join Date
    Oct 2013
    Posts
    1

    Re: How to use Report Viewer with Visual Studio 2012 Express

    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


    Quote Originally Posted by circuits2 View Post
    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.

    Name:  viewer1.png
Views: 50440
Size:  19.7 KB


    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.

    Name:  viewer2.png
Views: 50504
Size:  61.8 KB


    Navigate to the ReportViewer Runtime that you installed and select Microsoft.ReportViewer.WinForms.dll.

    Name:  viewer3.png
Views: 50607
Size:  113.1 KB


    Now you will find the Report Viewer control in your toolbox.

    Name:  viewer4.png
Views: 49891
Size:  10.9 KB


    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:
    1. Imports Microsoft.Reporting.WinForms


    This code assumes you know how to fill a datatable:

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

  10. #10
    New Member
    Join Date
    Aug 2006
    Posts
    9

    Re: How to use Report Viewer with Visual Studio 2012 Express

    Hello,

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

    A

  11. #11
    New Member
    Join Date
    Aug 2006
    Posts
    9

    Re: How to use Report Viewer with Visual Studio 2012 Express

    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...

  12. #12

    Thread Starter
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,025

    Re: How to use Report Viewer with Visual Studio 2012 Express

    Quote Originally Posted by amberHancock View Post
    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.
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

  13. #13
    New Member
    Join Date
    Jan 2014
    Posts
    1

    Re: How to use Report Viewer with Visual Studio 2012 Express

    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?

  14. #14
    Addicted Member
    Join Date
    Feb 2012
    Posts
    191

    Re: How to use Report Viewer with Visual Studio 2012 Express

    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.

  15. #15
    New Member
    Join Date
    Feb 2014
    Posts
    1

    Re: How to use Report Viewer with Visual Studio 2012 Express

    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

  16. #16
    New Member
    Join Date
    Feb 2014
    Posts
    1

    Re: How to use Report Viewer with Visual Studio 2012 Express

    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:
    Code:
    Me.MerchantsTableAdapter1.FillBy(Me.TestDataSet1.Merchants)
    Me.BindingSource1.DataSource = Me.MerchantsTableAdapter1
    Dim rds As New ReportDataSource("DataSet1", Me.BindingSource1)

  17. #17
    New Member
    Join Date
    May 2014
    Posts
    2

    Re: How to use Report Viewer with Visual Studio 2012 Express

    Quote Originally Posted by jeff@databae.com View Post
    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 ...
    Last edited by Quint; May 16th, 2014 at 10:35 AM.

  18. #18
    New Member
    Join Date
    May 2014
    Posts
    2

    Re: How to use Report Viewer with Visual Studio 2012 Express

    Quote Originally Posted by jeff@databae.com View Post
    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__…..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.