What you want to see on DotNetFunda.com ?
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 1531 |  Welcome, Guest!   Register  Login
Home > Articles > ASP.NET > Creating Sql Server Report (RDLC) using Dataset

Creating Sql Server Report (RDLC) using Dataset

Article posted by Sksamantaray on 2/15/2012 | Views: 10747 | Category: ASP.NET | Level: Beginner | Points: 250 red flag


Creating a Sql Server Report(RDLC) with the help of Dataset is straightforward task now.

Download


 Download source code for Creating Sql Server Report (RDLC) using Dataset


Introduction

Generally we create a strongly typed data-set during design time for creating a RDLC Report which is considered to be data-source for a Report, as we saw in our last article ( http://www.dotnetfunda.com/articles/article1778-create-ssrs-client-side-report.aspx ).But this dataset does not satisfy our requirement under all circumstances. so we may need to modify its data at run-time. To achieve this we can create a dataset and populate data and bound to data-source.
In this article we will see how a data-set can provide data to a report-viewer control at run-time. 

Objective

How to bind data-set and RDLC report to a Report-viewer at run-time.

Using the code

In our last Article we used a fixed query at design time i.e
select * from employees
This report always going to return all employees .However sometime we need to display employees of a particular country ,or employees of hired between a specified date range or employees of a city.
For that we can create a data-set and bind it to data source. In this article i will show how employees of City : London can be bound to Report-viewer. User Can use Drop-down or other controls to pass the value for the conditional queries.
Refer to my previous article : http://www.dotnetfunda.com/articles/article1778-create-ssrs-client-side-report.aspx
Steps:
1. Refer to your defined connection string of web.config.
 in general declaration section   :                                                           string connn = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ToString();
2. Bind your dataset data to Report-Viewer
// The original dataset will be cleaned and will have new set of data depending upon query output
// Here we want the output to be the employeedetails of city London                                                                                         protected void getData()
    {

        SqlDataAdapter da = new SqlDataAdapter("select * from Employees where city='London'", connn);
        DataSet ds = new DataSet();
        da.Fill(ds);

        ReportDataSource rdc = new ReportDataSource("DataSet1_Employees", ds.Tables[0]);
        ReportViewer1.LocalReport.DataSources.Clear();
        ReportViewer1.LocalReport.DataSources.Add(rdc);
        ReportViewer1.Visible = true;
        ReportViewer1.LocalReport.Refresh();
        
    }
3. Call your getData Method in Page_Load
 protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
           getData();
        }
    }
//Output

Once you get the output in Report-Viewer, can export to PDF or Excel using the red color highlighted dropdown and clicking on export button then.

Conclusion

This is how a dataset and RDLC can render data at run-time.


If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:



Please Sign In to vote for this post.

Experience:5 year(s)
Home page:
Member since:Sunday, November 06, 2011
Level:Silver
Status: [Member]
Biography:Scalable-Systems Pvt Ltd
>> Write Response - Respond to this post and get points
Related Posts

RFC is an open source initiative for Finance projects. It has reusable components like invoicing, accounting and purchase modules. In this section we will discuss about the invoicing section of the RFC architecture.

A tutorial video which explains step by step to enable your asp.net application to consume application services like Membership,Roles,Profiles etc.

In this article we shall learn how to generate a menu based on SiteMap file and how to generate Menu from the database.

This one is really very useful whenever we have a need to calculate running totals in the grid either row wise or in column wise.

In this article I will show you how to change the background and border color for controls that failed the validation in an ASP.Net application.

More ...
About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/26/2013 4:33:05 AM