In this article I will explain how to create crystalreports in asp.net.
Description:
In Previous posts I explained lot of articles regarding Asp.net, Gridview, SQL Server, Ajax, JavaScript etc. Now I will explain about crystal reports it is standard reporting tool for visual studio by using these we can display reports regarding employee details and display charts etc and crystal reports need minimal coding to display result.
In Previous posts I explained lot of articles regarding Asp.net, Gridview, SQL Server, Ajax, JavaScript etc. Now I will explain about crystal reports it is standard reporting tool for visual studio by using these we can display reports regarding employee details and display charts etc and crystal reports need minimal coding to display result.
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 Design mode after that open Toolbox from that drag and drop MicrosoftReportViewer control from Reporting tab
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
|
After click on Design a new report now welcome window wizard will open
|
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.
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
|
After click ok New database connection added to dropdown now click on Next button
|
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
|
After click finish our report wizard populate with our selected table now select that table and our Next button
|
After
click Next button it will display options to select Report type either
Tabular or Matrix now select Report Type and click Next Button
|
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
|
After
click Next button Report wizard will display option to select Table
layout after select required table layout click on Next button
|
After
click Next button Report wizard will display option to select Table
style after select required table style click on Next button
|
After
click Next button Report wizard will display Completing the Report
Wizard in that enter Report Name and click Finish button
|
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.
|
After that Now Open Default.aspx page and select ReportViewer and click smart tag in right side in that select Report Type
|
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
|
Please give your comments regarding above topic is it ok or not and if you like the post please share it.
Comments
Post a Comment