Subscribe to Subscribers
Talk to Webmaster Tony John

Online Members

Phagu Mahato
More...


Resources » Code Snippets » ASP.NET WebForms

How to display record in Crystal Report?


Posted Date:     Category: ASP.NET WebForms    
Author: Member Level: Diamond    Points: 10


In this article I have explained 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"];
try
{
sqlcon.Open();
//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";
}
else
{
query="select * from student where sid='" + sid +"'";
}
sqlcmd = new SqlCommand(query,sqlcon);
da = new SqlDataAdapter(sqlcmd);
dt.Clear();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
ReportDocument RptDoc = new ReportDocument();

RptDoc.Load(Server.MapPath("~/CrystalReport.rpt"));
RptDoc.SetDataSource(dt);

CrystalReportViewer1.ReportSource = RptDoc;
CrystalReportViewer1.DataBind();
}
}
catch(Exception ex)
{
Response.Write(ex.ToString());
}
finally
{
sqlcon.Close();
}
}
}
}

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#

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

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





  • Did you like this resource? Share it with your friends and show your love!


    Responses to "How to display record in Crystal Report?"
    Feedbacks      

    Post Comment:




  • 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:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: Different ways of using a Session for State Management
    Previous Resource: Create Online Exam Project with ASP.Net & C#.Net with JavaScript Timer
    Return to Resources
    Post New Resource
    Category: ASP.NET WebForms


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    How to use in Crystal Report in ASP.Net?  .  How to use xml dataset in Crystal Report?  .  



    Follow us on Twitter: https://twitter.com/dotnetspider

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.