How to Use Report Viewer in Visual Studio 2012

In my last article I explained how to create a SSRS project. In this article I explain how to use the Report Viewer in Visual Studio 2012. In this article we will see use of a dataset and the Report Viewer.

Step 1: Open Visual Studio 2012 or 2010 then create a new Forms Application (project name: "HowToOpenReportViewer").

Step 2

Report-Viewer-in-SQL-Server-1.jpg

  • Change the DropDownStyle to DropDownList
  • Design name: cbProducts

Step 3: We need to create a dataset. How? Right-click on the HowToOpenReportViewer project then select "Add" >> "New Item" then select "DataSet". The default name is "DataSet1.xsd"; I did not change it. Then click the "OK" button.

Report-Viewer-in-SQL-Server-2.jpg

Here is the default DataSet page.

Report-Viewer-in-SQL-Server-3.jpg

Step 4: Right-click then select "Add" -> "TableAdapter"

In this screen we can set a connection configuration. If you have no connection struct then you should create a new connection fron the "New Connection".

Report-Viewer-in-SQL-Server-4.jpg

Step 5

Report-Viewer-in-SQL-Server-5.jpg

Step 6: If you have Stores Procedures then you should choose the second button; I chose "SQL Statement". Then click the "Next" button.

Report-Viewer-in-SQL-Server-6.jpg

Step 7: We should use a SQL query for ComboBox.

Report-Viewer-in-SQL-Server-7.jpg

Step 8: This query will use a ComboBox.

Report-Viewer-in-SQL-Server-8.jpg

Step 9: Here is my method's name. If you want to change it, you can do that but I do not want to change it. I'll use the default name.

Report-Viewer-in-SQL-Server-9.jpg

Step 10: All the configuration is there. If you are not sure of the settings then you should click the "Previous" button.

Report-Viewer-in-SQL-Server-10.jpg

Step 11: I will create a DataAdapter two times for the display value.

Report-Viewer-in-SQL-Server-11.jpg

Step 12: Click the ComboBox then select "Use Data Bound Items".

Data Source: Products
Display Member: ProductName
Value Member: ProductID and then we see the ProductName in the ComboBox.

Report-Viewer-in-SQL-Server-12.jpg

Step 13: Click "Report Viewer" then select "Desing a new Report".

  • Write your DataSet name
  • Select your Data source and Available dataSet from the ComboBox

Report-Viewer-in-SQL-Server-13.jpg

Step 14
: Note the option here to group the data and show it. It depends on your report's structure.

Report-Viewer-in-SQL-Server-14.jpg

Step 15

Report-Viewer-in-SQL-Server-15.jpg

Step 16: Remember the SSRS Project :D In this page we see 6 default templates. I chose the Slate template and all of the users see that. Then click the "Next" button.

Report-Viewer-in-SQL-Server-16.jpg

Step 17

Report-Viewer-in-SQL-Server-17.jpg

Step 18

Add one button and name "Display".

Report-Viewer-in-SQL-Server-18.jpg

Step 19:
Click "Report Viewer" then select "Choose Report".

Report-Viewer-in-SQL-Server-19.jpg

And the result is here:

Report-Viewer-in-SQL-Server-20.jpg


Similar Articles