Showing posts with label Step by step to create rdlc report in .Net. Show all posts
Showing posts with label Step by step to create rdlc report in .Net. Show all posts

How to create rdlc reports in asp.net

In this Article I will explain how to create RDLC Reports in ASP.Net.
Finally my output looks like this.


I created a table with name Employee


Now I am creating an empty web application as shown


Right click on the solution add Report Wizard as shown below.

After adding report wizard, we have to configure Data source as shown, I am selecting my database.

Click Next->Next
Select the Database objects, I am selecting my table name and stored procedure name as shown ,Click Finish.

It displays dataset properties click Next

Drag the available fields 

Click Next->Next->Next->Finish.

Finally rdlc Design will display like this.

Now I am creating a web form with name Report.aspx, click Add

Now I am designing my UI as shown

  Drag the report viewer  and choose Report as our report name as shown  

Drag the script manger on the UI Screen.
Finally my UI looks as shown.

We can find the Report.aspx code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Report.aspx.cs" Inherits="RdlcExample.Report" %>

<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
     <div>
        <label>Name</label>
       <asp:DropDownList ID="ddlname" runat="server">
         <asp:ListItem>All</asp:ListItem>
        </asp:DropDownList>
        <label>Designation</label>
        <asp:DropDownList ID="ddldesignation" runat="server">
         <asp:ListItem>All</asp:ListItem>
        </asp:DropDownList>
        <label>Address</label>
        <asp:DropDownList ID="ddladdress" runat="server">
         <asp:ListItem>All</asp:ListItem>
        </asp:DropDownList>
        <br />
        <asp:Button ID="btnReport" runat="server" Text="GenerateReport"
            onclick="btnReport_Click" />

   
    </div>
    </div>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana"
        Font-Size="8pt" InteractiveDeviceInfos="(Collection)"
        WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt">
        <LocalReport ReportPath="Report1.rdlc">
            <DataSources>
                <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="DataSet1" />
            </DataSources>
        </LocalReport>
    </rsweb:ReportViewer>
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
        SelectMethod="GetData"
        TypeName="RdlcExample.Report">
    </asp:ObjectDataSource>
    </form>
</body>

</html>


    


    
All All All
Now I am implementing the Logic for generating report in Report.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace RdlcExample
{
    public partial class Report : System.Web.UI.Page
    {

        static DataTable DatTab { get; set; }
        //DataSet dt 
        public static string Name { get; set; }
        public static bool flag { get; set; }
        public static SqlConnection con = new SqlConnection("Data Source=CHINNU;Initial Catalog=dotnetdb;User ID=sa;Password = password123;");
        public static string Designation { get; set; }
        public static string Address { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                loadDdlDesignation();
                loadDdlAddress();
                loadDdlName();
                GetData();
              

            }
        }
        public void loadDdlAddress()
        {

            try
            {
               
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }

                SqlCommand com = new SqlCommand("select EmpAddress from Employee", con); 
                SqlDataAdapter da = new SqlDataAdapter(com);
                DataSet ds = new DataSet();
                da.Fill(ds);  

                ddladdress.DataTextField = ds.Tables[0].Columns["EmpAddress"].ToString(); 

                ddladdress.DataSource = ds.Tables[0];
                ddladdress.DataBind();
                ddladdress.Items.Insert(0, "All");
            }
            catch (Exception)
            {


            }


        }
        public void loadDdlDesignation()
        {

            try
            {
               
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }

                SqlCommand com = new SqlCommand("select EmpDesignation from Employee", con); // table name 
                SqlDataAdapter da = new SqlDataAdapter(com);
                DataSet ds = new DataSet();
                da.Fill(ds);  // fill dataset
                ddldesignation.DataTextField = ds.Tables[0].Columns["EmpDesignation"].ToString(); // text field name of table dispalyed in dropdown

                ddldesignation.DataSource = ds.Tables[0];      //assigning datasource to the dropdownlist
                ddldesignation.DataBind();  //binding dropdownlist
                ddldesignation.Items.Insert(0, "All");
            }
            catch (Exception)
            {


            }


        }



        public void loadDdlName()
        {

            try
            {
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }


                SqlCommand com = new SqlCommand("select EmpName from Employee", con); 
                SqlDataAdapter da = new SqlDataAdapter(com);
                DataSet ds = new DataSet();
                da.Fill(ds);  

                ddlname.DataTextField = ds.Tables[0].Columns["EmpName"].ToString(); 

                ddlname.DataSource = ds.Tables[0];      
                ddlname.DataBind();  
                ddlname.Items.Insert(0, "All");
            }
            catch (Exception)
            {


            }


        }
        public static DataTable GetData()
        {
            try
            {
                
                DatTab = new DataTable();
                
                if (!flag)
                {
                    SqlCommand cmd = new SqlCommand("select  * from Employee", con);
                    //cmd.CommandType = CommandType.StoredProcedure;
                    SqlDataAdapter adap = new SqlDataAdapter(cmd);
                    adap.Fill(DatTab);
                    con.Close();
                }

                else
                {
                    if (con.State == ConnectionState.Closed)
                    {
                        con.Open();
                    }
                    using (SqlCommand cmd = new SqlCommand("Show_Report", con))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add(new SqlParameter("@EmpName", SqlDbType.NVarChar)).Value = Convert.ToString(Name) == "All" ? "-1" : Convert.ToString(Name);
                        cmd.Parameters.Add(new SqlParameter("@EmpDesignation", SqlDbType.NVarChar)).Value = Convert.ToString(Designation) == "All" ? "-1" : Convert.ToString(Designation);
                        cmd.Parameters.Add(new SqlParameter("@EmpAddress", SqlDbType.NVarChar)).Value = Convert.ToString(Address) == "All" ? "-1" : Convert.ToString(Address);

                        cmd.ExecuteNonQuery();
                        SqlDataAdapter da = new SqlDataAdapter(cmd);
                        da.Fill(DatTab);
                        con.Close();
                    }
                }
                con.Close();
            }
            catch (Exception ex)
            {
                con.Close();
            }
            return DatTab;
        }

        protected void btnReport_Click(object sender, EventArgs e)
        {
            flag = true;
            Designation = ddldesignation.Text.Trim();
            Address = ddladdress.Text.Trim();
            Name = ddlname.Text.Trim();



            GetData();

            ReportViewer1.LocalReport.Refresh();
        }
    }
}
After completing all the steps Press F5 .

OutPut:




how to display page number in rdlc report

In this Article I will explain how to show Page number in the footer .

                      
Drag the TextBox from the Toolbox,in the footer area of the Rdlc Report.
                            
Right click on the TextBox select Expression.
                        
Under Category select Bulit-in Fields,there we can generate the expression to display the total no of pages in the report.
Now I am adding this Expression in that expression window and Click Ok.

="Pages " & Globals!PageNumber & " OF " & Globals!TotalPages
           


Press F5.
Now we can See the Out Put:








how to create rdlc report in c# windows application

how to create rdlc report in c# windows application


See my Previous Article for that Form1.I am designing my screen having,Combo Box, Two DateTimePicker and Button for Generating report.
How to Page number in rdlc reports
How to add no data found message in rdlc report
My Out Put looks like this,By default I will display All information.
If we select the combo box options and click on Generate Button,It will Show the Out Put Based on My Requirement




I Designed the Report Form UI looks like this.

                            

I  Design  database looks like this.



Now I am creating the stored procedure to generate reports based upon date selection.
See my Previous Article where we can select existing stored procedure.

USE [chinnu]
GO

/****** Object:  StoredProcedure [dbo].[SP_GenerateReport]    Script Date: 08/05/2013 04:15:41 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

create procedure [dbo].[SP_GenerateReport]

(
@StartDate DateTime
,@EndDate DateTime  
)                                
as
BEGIN

 SELECT EmpId,Convert(varchar,CreatedDate,101) As CreatedDate ,EmpName,EmpAddress
    FROM Employee
    WHERE  Convert(varchar,CreatedDate,101) between  @StartDate and  @EndDate    
    
  
END
GO




Finally my solution looks like this.






   Now write the code in Form1.cs                                                                                                                                                                            

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace RdlcReports
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            ddlperiod.Items.Add("All");
            ddlperiod.Items.Add("Today");
            ddlperiod.Items.Add("Yesterday");
            ddlperiod.Text = "All";
            // TODO: This line of code loads data into the 'DataSet1.SP_GenerateReport' table. You can move, or remove it, as needed.
            //this.SP_GenerateReportTableAdapter.Fill(this.DataSet1.SP_GenerateReport);

            this.SP_GenerateReportBindingSource.DataSource = ReportData();
            ReportData();
            this.reportViewer1.RefreshReport();
        }

        public static DataTable ReportData()
        {
            DataTable DatTab = new DataTable();
            try
            {

                SqlConnection con = new SqlConnection("Data Source=DotNetSharePoint;Initial Catalog=chinnu;User ID=sa;Password = Admin1234;" );
          
                con.Open();
                if (true)
                {
                    con.Close();
                    SqlCommand cmd = new SqlCommand("SELECT EmpId,Convert(varchar,CreatedDate,101) As CreatedDate ,EmpName,EmpAddress FROM Employee", con);
    
                    //cmd.CommandType = CommandType.StoredProcedure;

                    SqlDataAdapter adap = new SqlDataAdapter(cmd);
                    adap.Fill(DatTab);

                }

                else
                {



                }
                con.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return DatTab;
        }

        private void btnReprt_Click(object sender, EventArgs e)
        {
           string  Fdate = ddlstartdate.Text;
           string Ldate = ddlenddate.Text;


             DataTable DatTab = new DataTable();
            SqlConnection con = new SqlConnection("Data Source=DotNetSharePoint;Initial Catalog=chinnu;User ID=sa;Password = Admin1234;");
            con.Open();
            if (ddlperiod.Text == "All")
            {
                SqlCommand cmd = new SqlCommand("SELECT EmpId,Convert(varchar,CreatedDate,101) As CreatedDate ,EmpName,EmpAddress FROM Employee", con);
               

                SqlDataAdapter adap = new SqlDataAdapter(cmd);
                adap.Fill(DatTab);
            }

            else
            {

                using (SqlCommand cmd = new SqlCommand("SP_GenerateReport", con))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("StartDate", SqlDbType.DateTime)).Value = Convert.ToDateTime(Fdate).ToShortDateString();
                    cmd.Parameters.Add(new SqlParameter("EndDate", SqlDbType.DateTime)).Value = Convert.ToDateTime(Ldate).ToShortDateString();
                    cmd.ExecuteNonQuery();
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    da.Fill(DatTab);
                }
            }

            con.Close();
            this.SP_GenerateReportBindingSource.DataSource = DatTab;
            this.reportViewer1.RefreshReport();

        }

        private void ddlperiod_SelectedIndexChanged(object sender, EventArgs e)
        {

            var toDate = DateTime.Now;
            var fromDate = DateTime.Today;

            switch (ddlperiod.Text)
            {
                case "Today": fromDate = toDate; break;
                case "Yesterday": fromDate = toDate.AddDays(-1); toDate = toDate.AddDays(-1); break;
            
                default: break;
            }

            ddlstartdate.Text = fromDate.ToShortDateString();
            ddlenddate.Text = toDate.ToShortDateString();

        }
    }
}





Now Add AppConfig for DataBase Connection.

        
    

After Completing the Steps,Press F5.


OutPut:



Now Select Today Date Click on Generate Report,It will shows today's Information





How to create rdlc reports in c#


I Created a table in Sqldatabase as shown below. 
  










Now I am going to implement rdlc reports, using vs2010.

Create a new project 


Select the windows and select form give solution name as show below.
Click ok.


Right Click on the solution explorer select new item


Select the Dataset as shown below, Click on add.

After Clicking add It will displays  the Dataset like this

Right click on Dataset add TableAdapter


I will display TableAdapter Configuration Wizard.

Click on NewConnection .
Add connection window will display now.
Select the server name.
Select database name.
If we want test the connection,Click on test connection Click ok->ok.


Click Next


Click next.
Now we have to choose a command type.
I am doing with Sql select staments in this example.
Click next.


Select the Query builder as shown below



Select the table name, In my DB having only one table
Click on Add .






After adding Close the window.
In querybulider window i want to show all the colum’s information,so I selected all.
We can also test how the data will display but clicking the QueryBuilder and click Ok.
Click next.




Click next.


Click Next.and finally click finish.

Now,right click on solution explorer, click on add new item select the report wizard as shown below.


After clicking on add, report wizard window will display
Select the Data source name what we created in our solution.
Select available datasets.
Click on Next.



 In the arrange fields window,we have to drag all the fields as shown.





Click on next->next.


Click Finish.
We are able to see  .rdlc like this.






Now Click on Form1.cs,From Toolbox in Reporting drag the report viewer as shown below.


In the ReportViewer Tasks, select the Report.


After selecting, Press F5.

We can see output:



Labels

.Net Interview Questions add custom button in sharepoint using javascript Add custom column property into a PageLayout in SharePoint Add Page Title on their browser's title bar in SharePoint Customly add zip files in blogger Add-SPOSiteCollectionAppCatalog : Must have Manage Web Site permissions or be a tenant admin in order to add or remove sites from the site collection app catalog allow list Advance SmartObject An error occurred while accessing the resources required to serve this request. The server may not be configured for access to the requested URL. Angular 2 Angular JS Angularjs Angularjs 1 anonymous users accessing lists and libraries App Permissions for SharePoint 2013 asp.net membership unique email Asp.net TreeView Control asp.net. Attendees in SharePoint Auto refresh list using Content Editor WebPart in SharePoint 2013. Auto Refresh SharePoint list using JavaScript Block and unblock of attachment types in SharePoint Blogger C# Callouts in SharePoint 2013 Cascading Dropdown list in SharePoint change onenote to another location. change SuiteBarLeft in SharePoint 2013 check if userid exists in database c# click node text to expand/collapse in Treeview client object model Close webpart CQWP crate chart using BI site in PPS Create a modern team site collection in SharePoint online Create BI chart in PPS SharePoint 2013 create filter in dashboard designer. create kpi's in dashboard designer create kpi's in SharePoint 2013 dashboard designer Create List Create List In SharePoint Create List using Power Shell Script Create Lookup Field in List using Power Shell Script Create lookup field in List create SharePoint List custom view. create SharePoint List views in List Schema create site collection in site collection in SharePoint using powershell created Date Time calculated field in SharePoint Cross site Collection in SharePoint 2013 Crud Operation in Asp.net Using Stored Procedure Custom MasterPage Approval in SharePoint custom view for survey list Customly add SharePoint List view in Page. delete items in sharepoint using powershell Difference between Angular 1.x & Angular 2 difference between Office 365 and Windows Azure difference between Windows Azure and Office 365 in sharepoint? DifferenceBetween discussion board Display Data in Grid View display radio buttons and choice fields horizontally in SharePoint 2013 Document library DotNet Drag and drop documents in document library in SharePoint dynamically populating values from one list to another list using jquery in sharepoint edit and delete buttons in datagridview Edit Links email notification using Nintex enable anonymous access in SharePoint 2013 enable app catalog sharepoint online site collection powershell Enable appcatalog site collection level using PowerShell based on Input file Enable versions for list and library except the hidden lists using PowerShell Script Error occurred in deployment step 'Recycle IIS Application Pool': Cannot resolve model for the project package Errors&Solutions Export document library in sharepoint using powershell Export particular Group in Term Store Management in SharePoint 2013 Export to Excel first release Flow Flow features free disk space on servers using powershell Friendly URLs and Managed Navigation in SharePoint 2013 get a list of site collection with template in web application using PowerShell Script in SharePoint Get attachments in SharePoint custom list using c# get current list item id sharepoint programmatically Get current url using jquery Get data from SharePoint list using Rest api & Angular JS Get Random Get Random SharePoint items using PowerShell Get Random values from SharePoint list using PowerShell Get url of the last value using jquery Get-SPOSite : The managed path sites/yoursitename is not a managed path in this tenant. Getting Email From User Hide “Edit Links” in left navigation SharePoint 2013 hide button in sharepoint based on permissions Hide column in SharePoint List view hide fields using client side object model Hide list in Quick Launch in SharePoint using PowerShell How to add Custom Tiles to SharePoint site Page. How to add extension files in Search Navigation in SharePoint 2013 How to Add Multiple users Using SharePoint People Picker How to add SharePoint list view in Page using C# How to Approve MasterPage using PowerShell in SharePoint How to bind Multiple users Using SharePoint People Picker how to change indicators on kpi performance how to check if an email address already exists in the database in asp.net how to configure workflow manager platform for SharePoint 2013 how to create calculated value using powershell how to create certificate in SharePoint How to create flow. how to create gantt chart webpart in sharepoint how to create KPI indicators in Dashboard designer How to create moden communication site in SharePoint online How to create Multi selected filter in Dashboard How to create nintex workflow in sharepoint how to create rdlc reports in asp.net How to Display Data Grid View in ASP.net How to enable anonymous access in SharePoint How to find data in datagridview in c# How to get image names from the folder using C# how to get particular list content type id in SharePoint 2013 How to get QueryString value in SharePoint WebPart Programatically how to get the current item id for newly created item using REST API and JQuery how to hide list in sharepoint how to know who created list in sharepoint How to make a Site Collection Read-Only in SharePoint 2010 How to overlay Office 365 shared calendar on SharePoint Site how to pass jquery value to asp.net textbox control How to pass pagename as a browser's title bar in the page how to remove unused Application Pool in SharePoint how to remove zone using powershell script How to send mail to particular group of people using PowerShell how to update modified by and created by using powershell how to uplaod RAR files in blogger import csv data into sharepoint import data using powershell Import group to term store management using SharePoint 2013. InfoPath InfoPath Cascading Dropdown list Insert update delete in datagridview in C# winforms Integration from SharePoint to k2. K2 Smart Forms for SharePoint JavaScript Injection jquery K2 blackpearl K2 Designer K2 Designer Workflow. K2 smartform cascading dropdown list k2 Workflow K2 workflow to send a mail with PDF left navigation Local Term Set in managed meta data Managed meta data navigation in SharePoint 2013 Managed metadata service in SharePoint 2013. Managed Navigation in SharePoint 2013. Managed Promoted Sites. meta data navigation Microsoft Flow New Features New-SPConfigurationDatabase The user does not exist or is not unique NintexWorkFlow Office 365 OneNote overwrite existing document in sharepoint using javascript PDF Converter PDF Method in K2 Performance Point Service in SharePoint 2013 PerformancePoint Services Configurtion PerformancePoint Services Configurtion for SharePoint 2013 PerformancePoint Services in SharePoint Server 2013 Popularity trends in SharePoint 2013 Pages populate dropdown list dynamicallyusing jquery Power Shell Power shell script to get SharePoint site size. powershell read xml PowerShell Script PowerShell script to get list of users from SharePoint groups PowerShell Scripts in SharePoint 2013 Powershell to set the masterpage in SharePoint Promoted Links Promoted Sites psconfig.exe quick launch Rdlc reports Readonly Column in SharePoint Editview Realtime DotNet Interview Questions Recent Dotnet interview questions Recent SharePoint interview questions recover deleted OneNote page. OneNote content is missing Regional Settings in SharePoint 2013 Replace New Item text in SharePoint Rest API Schedule PowerShell Script Search in SharePoint 2013 Search navigation in SharePoint 2013 Secure store service SecureStore Services SecureStore Services configuration for SharePoint 2013 self-signed certificate on IIS Server Send email to members of SharePoint Group using PowerShell sharepint2010 sharepoin2010 SharePoint 2013 SharePoint 2010 SharePoint 2013 SharePoint 2013 Dashboard Designer SharePoint 2013 features SharePoint 2013 Interview Questions SharePoint 2013. SharePoint 2013.disable views from user to create SharePoint 2013.Power shell SharePoint 2013.SharePoint 2010 SharePoint 2016 SharePoint Administration SharePoint Alerts and Reminders SharePoint App Configuration SharePoint Apps SharePoint Bulk upload SharePoint Calculated field SharePoint Calendar View sharepoint interview questions SharePoint online training SharePoint Onprem vs Online SharePoint RealTime Online Training SharePoint2010 SharePoint2013 SharePoint2016 SharePointInterview SharePointOnline SharePointOnline;Restore deleted site;SharePoint 2013 show data in datagridview in C# Simple Insert update Delete Retrieve Clear in asp.net. Site Collection Operations in SharePoint 2013 Site Collection Read-Only in SharePoint 2013 site contents Sorting & Filtering SPSite Site Collection Operation parameters in SharePoint 2013 Step by step to create rdlc report in .Net Store names in text files in C# Sub site Subsite Term store management. The server was unable to save the form at this time. please try again UI New look update created by using client side object model update field values in SharePoint using powershell update items in SharePoint list using client object model update modified by field using client side object model upload zip files in blog use IsNullOrEmpty in PowerShell VirtoSoftware VirtoSofware vitrosoftware WebParts what is Document Set in SharePoint 2010 What is Filter in SharePoint Dashboard what is Limited-access user permission lock down mode feature What is Modern Team site What is Target Audience in SharePoint Who Created Site Using PowerShell Workflow in SharePoint 2013 Workflow management platform in SharePoint 2013 Workflow manager for SharePoint 2013 XSL-Template.