What is Crystal Reports?
Crystal Reports is a database reporting application. It has powerful capabilities to access and analyze various sources of data for its reports.
Note: Please do comment for suggestions and improvements for me to update my first tip/trick entry. Thanks!
Steps in Making Crystal Report
First, you need to download the complete package in:
*VS = Visual Studio
For VS2010:
http://scn.sap.com/docs/DOC-7824
For VS2008:
http://scn.sap.com/docs/DOC-27917
After Download and Install.
- Create a new project.
- Add a CrystalReportViewer to your WebForm.
Select the project name and then perform
the following:
- Add
New Item
- Select
Report and then select Crystal Reports
- Save
your File as "StudentList.rpt"
Just
close the dialog box that appear or
select Blank Report
A Blank report will be created.
Now, select the project name and then perform
the following:
- Add
New Item
- Select
DataSet
- Save
your DataSet as
"StudentRec.xsd"
- Drag
a table from your Sever Explorer going to your DataSet designer.
Go back to CrystalReport.rpt.
Create a class Library and named it as "ReportHelper
" and
then rename the Class as "DataReport
" and then write the following code
below:
Note: This is the code when you are using a DataSet.
using System.text;
using System.Data;
using System.Data.SqlClient;
namespace ReportHelper
{
public class DataReport
{
private static string _connString = @"Data Source";
public static DataSet LoadReport()
{
SqlConnection myConn = new SqlConnection(_connString);
SqlDataAdapter da = new SqlDataAdapter("Select * from StudentRecord", myConn);
DataSet ds = new DataSet();
da.Fill(ds, "StudTable");
return ds;
}
}
}
On Page_Load
event write the following code and then run your application.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ReportHelper;
using System.Data;
using System.Data.SqlClient;
namespace CrystalReport
{
public partial class WebForm1 : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e)
{
DataView dview = new DataView();
dview.Table = DataReport.LoadReport().Tables["StudTable"];
StudentList myreport = new StudentList();
myreport.SetDataSource(dview)
CrystalReportViewer1.ReportSource = myreport;
CrystalReportViewer1.DataBind();
}
}
}
I hope that this Tip may help you to understand and create a simple but useful Crystal Report.
Thank you for reading my tip.
-Jason P.