As, I mentioned in my post,
Load Reports without SQL SERVER Reporting Service with Asp.Net, we can develop
a report without SQL SERVER Reporting Service. That is very simple to do with Microsoft
Visual Studio. Please follow the following steps to generate simple report which
can be load in browser without SQL SERVER Reporting Service.
We need to follow following steps to generate simple report with RDLC:
- Create RDLC file.
- Create Dataset from Report Data Source.
- Design the Report
- Runtime pass information to Report Data Source, so report will be generated with
Let's create one simple web application with RDLC report.
1. Create RDLC file:
- In Solution Explorer, add a new folder and name it as "Reports".
- Right click on "Reports", select "Add" and click on" New Items".
- Give preferable name to report with extension RDLC and click Add.
2. Create Dataset from Report Data Source:
- Click on "Report Data" tab displayed on left side of the screen and in case, it
is not displayed go to "View" menu and click on "Report Data".
- Click on "New" and select "Dataset" as displayed in following screenshot:
- If your "Data Source" is listed in options, select it from there, else click on
- If your "Connection" is listed in options, select it from there, else click on "New
Connection", to make your connection.
- Once "Connection" is selected, select your Table/View/Stored Procedure/Function,
from which you need to build your report and give appropriate name to Dataset:
- Once you have selected DB Object in Dataset, you can find out all the columns that
are available in selected dataset as follows:
- Once you have this dataset, you will also find that one XSD file is also created
in App_code folder, with the same schema, which is used to provide schema definition
to RDLC file
3. Design the RDLC Report:
In Step #2, we have created Dataset with columns that needs to be displayed on the
report. Now its time to use that Dataset and design the report.
You should drag, "Table" from "Toolbox" and assign property "Dataset" created Dataset
in Step #2.
- RDLC, allows you to design your report with schema that you have selected as DataSet
So far, we have done report designing, now its time to pass actual data to the Report
Data Source, so report will be generated with actual Data. To display report on
the browser, we have to use "Microsoft Reporting WebForms", which will load the
report in the browser with ASPX page. Please follow the steps to pass information
to RDLC Report:
- Add an "aspx" page in the solution.
- We have to use "Report Viewer" control on that page, in which our Report will be
- We also need to add few lines of code, to dynamically pass the information (actual
data) to the Report Data Source as follows:
public partial class Reports_ProjectDetail : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
string connectionString = ConfigurationManager.ConnectionStrings["PISConnectionString"].ConnectionString;
Database db = new SqlDatabase(connectionString);
DbCommand command = db.GetStoredProcCommand("ReportProjectDetail");
DataSet dataset = db.ExecuteDataSet(command);
ReportDataSource datasource = new ReportDataSource("DataSet1", Dataset.Tables);
ReportViewer1.Visible = true;
Let me explain how it works:
- On Page load, we call one stored procedure to get data from database. Here I have
used Microsoft Application block to connect to database and get the information
- Once, we have the data in DataSet, we have created new "Report Data Source" with
the SAME name: "Dataset1" and assign result table as per #1 and assign it to ReportViewer
- And at last we refresh ReportViewer to display the information as per Datasource
This report is ready and you can export it in Excel, PDF, Word etc. This example
is developed in Microsoft Visual Studio 2010
Let me know your comments and difficulties, if any
Republished from SQL Yoga [33 clicks].
Read the original version here [32134 clicks].