Crystal Report using C#
1- use crystal reportviewer and create crystalreport.rpt file and make xml file for structure of data you want to show in report.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;
public partial class _Default : System.Web.UI.Page
{
SqlConnection con;
SqlCommand cmd;
DataSet ds;
SqlDataReader dr;
SqlDataAdapter adap;
public _Default()
{
con = new SqlConnection("data source=om-pc; initial catalog=demo; integrated security=yes;");
ds = new DataSet();
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
ReportDocument objrepdoc=new ReportDocument();
DataSet ds = GetRecord();
if (ds.Tables[0].Rows.Count>0)
{
try
{
ds.WriteXml(Server.MapPath("abc.xml"));
objrepdoc.Load(Server.MapPath("CrystalReport.rpt"));
objrepdoc.SetDataSource(ds);
objrepdoc.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Response, true, "ExportedReport");
}
catch
{
}
}
}
public DataSet GetRecord()
{
con.Open();
cmd = new SqlCommand("abc", con);
cmd.Parameters.AddWithValue("@id", txt.Text.Trim());
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter adap = new SqlDataAdapter(cmd);
adap.Fill(ds);
return ds;
}
}