In this article we will be exploring the RDLC reporting feature of .NET.In VS 2010 Crystal Reports are not supported and to create Reporting Systems we can use rdlc feature.
There are many times where we need to implement reporting functionality in the project.MS Visual Studio has given us an inbuilt tool to serve the purpose known as RDLC Reporting.
RDLC feature allows us to generate reports in very quick time.
Create Reports in Windows Application using RDLC Feature.
Using the code
Go to MS Visual Studio 2010 -> Open a New Project -> Select Windows Application.
Now right click on the Project Name and Add A Folder and Name it as Reports.
Now Right Click the Folder that we have just created and Select Add New Item and Search for Report.
Select the report and Name it as SampleReport as shown in the Image.
Now Right Click on the Project Name again and Select Add New Item -> Look for Dataset. -> When Found Select it and Name it as SampleDataset.
Once done adding the dataset below screen will be visible.
Now Right Click on the Empty Region and Select Add New Table Adapter as shown in the Image.
Once the adapter is added configuration wizard will ask to Choose the Connection as in the Screen below.
Select New Connection and then Select Server and Database and Authentication Mode.
Authentication Mode will depend upon how you connect to SQL SERVER.
In this case, we have a Password to SQL server which will let us use SQL Server Authentication.
Please check the Images below.
Now Click on New Connection but as seen in the Image and then Select the Server and Authentication Type and Database. Check the Below Image
Dot(.) can be for local Database in the place of SQL Server.
In this case, SQL Server has SQL Authentication and its user name is sa and password is sqluser.
Then we have selected the database as DotnetFunda.
Lastly we check the connection by clicking the Test Connection Button and it succeeded.
Check the Below Image.
After this click OK and then click next.
Note :- If your server has SQL Authentication then it will ask you that do you want to show sensitive data i.e. the password for connection to SQL, select Yes.
Then the wizard will ask to save the connection string in the AppConfig File. Save it and then Click Next.
After this it will ask on how we want to get the data from tables. In this there are 3 options.
- Use SQL Statement :- This will ask to write SQL Query to fetch data.
- Create a New Stored Procedure :- This will ask to create a new Stored Procedure to fetch data.
- Use Existing Store Procedure :- This will select if already a Stored Procedure is created in the database.
In this article, we already created the Stored Procedure to use existing Store Procedure.
Check the Image below
Once selected the Option Click Next.
After Clicking Next, Wizard will ask to select the Stored Procedure. Since we are fetching the data we will select the Stored Procedure from the Select Drop Down as shown in the Image.
In this case my Stored Procedure Name is getDataforMonth.
Now Click Next after selecting the Stored Procedure. After Clicking Next it will let us choose method to generate form. In this let both the option i.e. Fill a Data Table and Method Name as it is and let it be checked.
Refer the Image as shown below
Now Click Next and then it will take us to Wizard Results form, click finish.
Here is the Image for the Above Step
Now we have configured the Data set.
Now go to the Report Folder and open the Report Designer by double clicking the SampleReport that we have added in the Earlier Steps.
Now go to the Tool Box and add a Matrix Control to the Toolbox .
The Matrix control will display data that we are fetching the database.
As soon as we drag and drop the Matrix Control we will be asked ask to set the data set properties.
Give a name to data set for the Matrix Control.Be careful while giving name because this name we will use it in our code behind on the Windows form as a Reference to the dataset for matrix Control.
In this article, we used the name, rajdataset.
Then select the data source as we SampleDataset that we have configured in the earlier Steps. Once we select it the third drop down for available dataset will automatically be filled.
Now Click ok.
Check the Image.
Now start designing the matrix and assign the Properties to the textbox in the Matrix.
Right Click on the data row and select text box Property and then Add the Value as Month from the drop down of Value and on another column add it as Population for other text box in the matrix
Check the Image.
Now we will get the table as shown in the Image.
Now come to the windows form in our Application and drag and Drop a report Viewer from the toolbox under Reporting.
Now on the Right hand side there will be an arrow to select the report to be shown in the report Viewer.
Check the Image.
Select the first report that you see i.e. Sample Report.Once you select it you will see on the bottom you will get to see the dataset you created and Table Adapters and methods.
Check the Image
Now Come to the code behind add the following namespace
It will automatically get the data from the Database.Since we do not have any parameters to Stored Procedure
// Code behind
public partial class Form1 : Form
private void Form1_Load(object sender, EventArgs e)
// TODO: This line of code loads data into the 'SampleDataset.getDataforMonth' table. You can move, or remove it, as needed.
Output after executing the Application.
Hope this will be a good resource.