Getting Started With Reports in .NET

Technology used : Visual Studio 2012 and SQL Server 2008

Step 1: Create a database named "Test" in SQL Server 2008 that holds a Table called "Employee" with 3 columns (ID, Name and Salary) , where the ID column is an Identity field and a Primary Key as in the following:

CREATE TABLE [dbo].[Employee](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Name] [varchar](50) NULL,
[Salary] [int] NULL

CONSTRAINT [PK_Employee] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
ON [PRIMARY]
) ON [PRIMARY]

Then insert some data into the table as in the following:

insert into Employee (Name,Salary)values('A',50000)
insert into Employee (Name,Salary)values('B',10000)
insert into Employee (Name,Salary)values('C',60000)
insert into Employee (Name,Salary)values('D',20000)
insert into Employee (Name,Salary)values('E',10000)
insert into Employee (Name,Salary)values('F',70000)
insert into Employee (Name,Salary)values('G',40000)


select * from employee


Step 2: Create a new empty website named "RDLC_Start".


Step 3: Create a new page named "Default.aspx" by right-clicking on the project in Solution Explorer and click on "Add" -> "New Item".






Step 4: Add a ‘ScriptManager’ from the Ajax Extensions section, ‘SQLDataSource’ from the Data section and ‘ReportViewer’ Control from the Reporting section on the page.



Step 5: Right-click on the Selected ‘SQLDataSource’ control in Design Mode and use the following procedure:

  1. Click on "Configure Data Source", it populates a new window of Data Sources.
  2. Click on the "New Connection" button of the window, it shows the new connection window where you can fill in the details as mentioned:

    Select the "Microsoft SQL Server (SqlClient)" as Data Source

    Your Database Instance Name as SeverName

    Use SQL Server Authentication Mode as "Long on the server"

    Type the usrename as "sa" and enter the password of your database.

    Select the Database Name as "Test".

    And click the "OK" button.


  3. Now click on the "Next" Button.

  4. Check the checkbox and click on the "Next" button.

  5. Click on the "Next" button

                  a) Select the table named ‘Employee’ from the dropdownlist

                  b) Checked the columns that you want to display in your report


 



  1. Click on the "Finish" button.


Step 6: Add a RDLC file named ‘Report.rdlc’ by right-clicking on the project in Solution Explorer and click on ‘Add -> New Item’



Step 7: Right-click on the report and insert the table.



Which populates a Dataset window. Click on the New button of the Data Source and select the connection string name in the new window that you have created earlier in SQL DataSource on the default page.



Click on the next button and expand the "Tables" tree view and put a check on your table named "Employee" and click on the "Finish" Button.

Click ok on ‘Ok’ button of parent ‘Dataset window’.


Step 8: Your table will look like this:



Select each column by clicking, delete the extra column and saving it.



Step 9: Right-click on the "ReportViwer" Control after selection of the "Default.aspx"page and choose the "Report.rdlc" and save the page.



Step 10: Now run the page and see the output.


Up Next
    Ebook Download
    View all
    Learn
    View all