How to display record in Crystal Report?

In this article ,I am explaining about how to use crystal report in ASP.Net for bind data base record details. We can bind data in crystal report with help of xml tags or xml data set, here I have used XML dataset for bind records with crystal report.

How to create XML dataset with SQL Server table details?
Create dataset: Right Click your project name -> ADD new Item ->select dataset (DataSet1.xsd)
Then right click of that dataset and add new column (for your field names, types) as same like in the SQL Server table field names. .

How to connect dataset and CrystalReport Page in ASP.Net?
Right Click your project name -> ADD new Item ->Choose Crystal report and name (like this CrystalReport1.rpt).
Choose Field explorer in Left side and right click database Field -> Choose Database expert->choose new ADO.Net connection in tree and choose your dataset path and click finish.
Then your fields are displayed in field explorer drag and drop in to crystal report.

How to bind records in crystal report?
In this application I collect individual student id (or all) from client show all record details in the crystal report.

using System.Data;
using System.Data.SqlClient;
using System.Configuration;

using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.Web;
using CrystalDecisions.ReportSource;

public partial class Default2 : System.Web.UI.Page
SqlConnection sqlcon = new SqlConnection(ConfigurationManager.ConnectionStrings["Con"].ConnectionString);
SqlCommand sqlcmd;
SqlDataAdapter da;
DataTable dt = new DataTable();
string sid,query;
protected void Page_Load(object sender, EventArgs e)
if (!Page.IsPostBack)
sid = Request.QueryString["sid"];
//Check whether query string have value or not if not have value then select all record in below query otherwise select particular record with help of where condition
if(sid=="" || sid==null)
query="select * from student";
query="select * from student where sid='" + sid +"'";
sqlcmd = new SqlCommand(query,sqlcon);
da = new SqlDataAdapter(sqlcmd);
if (dt.Rows.Count > 0)
ReportDocument RptDoc = new ReportDocument();


CrystalReportViewer1.ReportSource = RptDoc;
catch(Exception ex)

Source Code Detail:
Here with I have attached source code to show student detail in crystal report. Download it and try to learn crystal report concepts.
Front End : ASP.NET
Code Behind : C#

I hope that this Article is help to you understand crystal report concepts.


  • CryExample_ASPNET (42857-311013-CryReport.rar)
  • Comments

    Guest Author: Hassan30 Apr 2013

    Hi, i have a problem for crystal report id generate i used id generator function code but it generate only one or two records then stop. Please help me that one.

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: