Groups > Asp .Net > ASP.NET Tips and tricks > Creating Crystal report using DataSet




Creating Crystal report using DataSet

Creating Crystal report using DataSet
Sun, 23 Mar 2008 17:15:19 +000
Creating Crystal Report in ASP.NET with DataSet

First we need to create a DataSet

Right click on website name in solution explorer and select ADD NEW ITEM from
that select DATASET.

Always give meaningful name to your dataset because we need to refer the same in
our code, here I’ve given “DS_Northwind”





After that, Add Table adapter s in the DATASET. Here also we have to give
meaningful name for our Table adapter, Data Table and for the Method



Save the Dataset and now we have our DataSet. Now we have to add a crystal
report and a webform to our project. 

Add crystal report from the template  and give report name accordingly.



Click “ADD” button. Now you’ll see the following screen.



Accept the default setting and click OK. From there we’ll point out our
Dataset for report’s source 



Select “ADO.NET Datasets” as your project Data and select the dataset what
we created early Now press “>”  and click Finish. You can click next too
to select fields to display in the report. At this time we are going to do that
manually. 



From field explorer, add required field into your report and set space
accordingly.

Now we are going to add chart into our report. Select  chart from the toolbar



After clicking this you’ll get chart construction panel. See the fig.



Select chart type and press the DATA Tab to define values for chart



I used Product Name and the unit price as my Data for the chart.  We can change
caption, series heading etc in TEXT tab. Now click ok.

Now we need to place the fields from database field to our report by dragging
them to our report. The heading will be changed further meaningfull otherwise it
shows the Database field name by default.



Now I added the database fields and changed the Heading.

Now we need to add web form to display the report. 

Add Crystal Report viewer into the added web form. This is the aspx page code
(HTML Markup) :<%@PageLanguage="C#"AutoEventWireup="true"
 CodeFile="Default.aspx.cs"Inherits="_Default"%>
<%@RegisterAssembly="CrystalDecisions.Web, Version=10.2.3600.0,
Culture=neutral, PublicKeyToken=692fbea5521e1304"   
Namespace="CrystalDecisions.Web"TagPrefix="CR"%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0
Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.
dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="se
rver">    <title>Untitled
Page</title></head><body>   
<formid="form1"runat="server">    <div>       
<CR:CrystalReportViewerID="crviewer"runat="server"AutoDat
aBind="true"/>    </div>   
</form></body></html> 

This is the ASPX.CS page(Code Page)using System;using System.Data;using
System.Configuration;using System.Web;using System.Web.Security;using
System.Web.UI;using System.Web.UI.WebControls;using
System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using
CrystalDecisions.Shared;using CrystalDecisions.CrystalReports;using
CrystalDecisions.CrystalReports.Engine;using DS_NorthwindTableAdapters; //
include our dataset herepublicpartialclass_Default : System.Web.UI.Page{   
protectedvoid Page_Load(object sender, EventArgs e)    {        TA_Products
products = newTA_Products();        DataTable DT_products = newDataTable();     
  ReportDocument RptDocument = newReportDocument();        
RptDocument.Load(Server.MapPath("Products.rpt"));       
RptDocument.SetDataSource(DT_products);        crviewer.ReportSource =
RptDocument;        crviewer.DataBind();    }} Now run You get   Happy
programming.
Post Reply
about | contact