Wednesday, 9 October 2013

How to Create Crystal Report in asp.net

How to Create Crystal Report in asp.net
To implement crystal reports first design the table in database and give name UserInfomation

ColumnName
DataType
UserId
Int(set identity property=true)
UserName
varchar(50)
FirstName
Varchar(50)
LastName
varchar(50)
Location
varchar(50)
After completion of table creation enter some dummy data because we need to use that data to populate reports. Now Open visual studio 2008 and create new website and open Default.aspx page in Designmode after that open Toolbox from that drag and drop MicrosoftReportViewer control from Reportingtab 
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8ObOXt2F77twh8fyGEU0rPZKWIGUPEJFdyxmJX_ufXstr2Nr-aZ4lFSYH7pgapQtY8Sko1nE2vWuANSmSwFjsYBFcL4YuOfWDp29MHCpHECfyE8E__R_SgbyqwlWFYhyarcgV0CekgTs/s1600/ReportingTab.png
After drag and drop MicrosoftReportViewer in your page select ReportViewer control and click on smart tag in right side and select Design a new Report 


https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNexjzAZYAL2wG0U_JHE8Vbr4eaRgP1w_AxA3p2nftuTx3-FRADIZBtnMfmQ1k2En7_S-1wCtfxKp3_dy8acZ_5FrWJeKF_3bp2beGTdE0znw-K9xQSQbMkaX-LbrfW6tBdfrHvz6aLVY/s640/DesignReport.png


After click on Design a new report now welcome window wizard will open

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwqOg3eo-JKnR4NaMAt7otbEsj53OH95hIb5LBMsFerZNXYs_iZXuQn76Nz206m-9jbXqYb1WpQYDcrby1Lg7hS7p63_NAo5VAUd00ByG2D0tevo2xCBjjjRzbmwYCJ7-4nL6hAed6jI4/s400/WelcomeWizard.png


Now click on Next button after that new Data Source Configuration Wizard will open in that click on New Connection button to configure database connection.  


https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDArS2D3OucegxmHtJnqqjycLgzpmyWU3HsXi4oo3famhUsDh2rUdPnjLddDlp7ZX2kgpuz5iTF5IgC8BN2_jnbnCgxHvt2Fwf5YaNFqTYnNq1Pt7gfpClunIWjfHOrBhs3wlq7XOHPRk/s400/NewConnection.png


Now one window will open to add new connection in that enter Server Name and select authentication type either windows or SQL Server and select database name after fill all the details click on Test Connection if the connection path is correct then that will display Test connection succeeded. After that click ok  

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTuBL1WYmY4DyAQVCj0GV1Z4SIOrK9H-FxX16towl0-N10qUzEZhCgZmrejQO1k0x7VPLGEYhCcqj9l3E0PUJuW4f9ANXiesPUcXfbkqmPNUCbw6JsRtIe1gWcbpKCo3sbRirsYmc7_4w/s1600/AddConnection.png


After click ok New database connection added to dropdown now click on Next button

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvrzoNJOpDypVercRtAH45f0IDwiXpLMP6D4AEtC-DwDVAWrtYgvR72gHyGNcGGRAC4R4U71s8sK-DaTJQFVPL1wJlyheB2GPcoBy-CCAjbdViDI4r8a-IWeVxsN1J7_SjrIdgPqXTctw/s400/DataSourceConfiguration.png
After click Next it will display available Tables, views, Stored Procedures and Functions in DataSource Configuration Wizard in that open Tables section and select required table previously we created table with name UserInformation now I am selecting that table from available list

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhV-5mj5yLOOs7KOMJJNtGRenDXPQuptWRXQBsGqUcPpmMlEGMYt3x3_Q2_3n6s0KGXDZFncs7lhh9bfbCvV_gcUsUd48uHfTJ7EYr1JTc_U-PFJVTNWq8zOE9cfgE7FI5-7p28wjB1RE4/s1600/TableSelection.png


After click finish our report wizard populate with our selected table now select that table and our Next button

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfL71V2-hEKpvZrieJq1vB2DZ2x2yeS2SDbwU_r7olcElSZ1SmPekjbLcCGSBWsRNzmbe1vM-jNLIQDrIrV5ml1TVbZS1_dk-bWbHHB0cpA5oFGWa2hxxUFUacI_-U-r-xKqyksjbZFvU/s400/ReportWizard.png


After click Next button it will display options to select Report type either Tabular or Matrix now select Report Type and click Next Button

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEir-6aEwdR1oQirMknE_5hqFFLWbVDGe7CftlXNyGkpoXiiId0zDy6N_tNJx9gLlw0zpD7dG8pD3nOCJi_MRJOYLqiGbk36sHuHisYwLfA8sybtyltRZBaQRcoHLY4GGjYRHFV_OgKNKCk/s400/ReportType.png


After click Next Report Wizard display Design the table option with available fields from previous selected table and give options like Page, Group and Details these are used to display the data based on Groupwise etc. Here we are doing simple crystal report sample I am not doing anything simply click on Next Button

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgq3DHEVefZATdr95YhIllPeUyeU7kPbN7LOiNpSKRKK6YNwYN-GCet9SASKIe-Dn6ZlkSMh80v4tB5Pb4kVgTojmtBusckhoccPPO623W0-FgawwXW4cMJVs4hBcQfOZ8T6TrMnzTrKiY/s400/DesignTable.png


After click Next button Report wizard will display option to select Table layout after select required table layout click on Next button

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVKh10GEoi1OIw_SSTpVNs-vc-6UCSuX2GMckzMXPKNj7c6Z6cJZ2n-pa76JrH7D_BnzsgKTNrrf8b6zch69S32a5DH_OO-1FQMG8-xvUb5665Uy0UXDDPYN35_AvXYSUW8QhyQ_saNAg/s400/LayOut.png


After click Next button Report wizard will display option to select Table style after select required table style click on Next button

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiM3I4d9JiiEE0AcHVKyUnnAB66mr29tEeb7LWttmTpzobM1b_Oxq0OwWQhqqgWhCWSSPAWhok8upJP_dvGfMhfjSfhAkifSuv0sACguc7saOcT_Ax-OfhRTq72_aaof5idEk-L6nexjsI/s400/TableStyle.png


After click Next button Report wizard will display Completing the Report Wizard in that enter Report Name and click Finish button

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgeHSiVrXdMCQgzp6xYvRJr6ZN9ZZLYhtxdOE6h73Vwb6nEQQpTy50CtOm-yY2g7QzBAVnrL01UJke60Q2q6edPevYAVmgZYHV1xPLdfBO7ztOrxNFGnxYj-OJBrTH0tX6u0ONUL7v2Pe8/s400/CompleteReport.png


After click Finish button now it will create new report if we open our website Solution Explorer we have chance to see newly created report Report1.rdlc and xsd file in App folder this xsd file contain our selected database table.

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgk-POT-VNzuHdFkfRyjhBLwtugDJK3E6ODEpBFN1ZltdsLpo_CgKe3wm1o4pjOx2HtHEEnA9jd7pkeFIvXAFe-ZqOfyLhklvcHNfKKgvLz3mgQ79tX1610FvZtJDSdMOa0q1NCF7gNfcc/s1600/SolutionExplorer.png


After that Now Open Default.aspx page and select ReportViewer and click smart tag in right side in that select Report Type

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcmc9UxEJbc7-ZNCmsn__2og2iaCvtQV_h4pRfuJL2w0tS2mpUnvKK5x8KNFOS1b3jCz4nGThgCzpFUcwTcJw6tw57T2HHh1Z4cQ2mKlW7IC5lfjkbdh2A6pYYagV2GOzutggCrlsPqm8/s640/SelectReport.png


Once Report1.rdlc selected Open Default.aspx Source code it contains code like this


<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=9.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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana"
Font-Size="8pt" Height="342px" Width="398px">
<LocalReport ReportPath="Report1.rdlc">
<DataSources>
<rsweb:ReportDataSource DataSourceId="ObjectDataSource1"Name="MySampleDBDataSet_UserInformation" />
</DataSources>
</LocalReport>
</rsweb:ReportViewer>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetData"
TypeName="MySampleDBDataSetTableAdapters.UserInformationTableAdapter">
</asp:ObjectDataSource>
</div>
</form>
</body>
</html>
If you above code Here we added referece of assembly for Reportviewer that is necessary to run our report perfectly. Now Run your application check the output that would be like this.


Demo


https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlgzj6XivY9OytxXL4GqUaaFeNkj4IN-plVNJe-0yb2KqeLMGeQiYEyC3OwQApyNmQdwfUMR3V8gt1dhlZzfg3AJOJYX_yVqu4f4geQ2sYNzO0aJWnA-sfz9mSrZtb4qTHII02W_1JigI/s1600/Demo.png




8 comments:

  1. Nice blog, keep writing like this


    Find here online price details of companies selling Mattress Cover Cotton. Get info of suppliers, manufacturers, exporters, traders of Mattress Cover Near Me for buying in India.

    ReplyDelete
  2. Nice blog, keep writing like this

    Buy Milwaukee at low prices in UK. Select from range of home improvement tools & Milwaukee UK of all brands from tools4trade.co.uk

    Milwaukee
    Milwaukee UK
    Milwaukee Power Tools
    Milwaukee Fuel
    Milwaukee UK Cordless
    Corded Power Tools
    Milwaukee power tools UK

    ReplyDelete