Asp.Net Crystal Report From XML File

Crystal Report From XML

To Generate Crystal Report From XML File in Asp.Net use followinf  code

Here Report.XML is an XML file in application

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 System.Data.SqlClient;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;

public partial class _Default : System.Web.UI.Page
{
CrystalDecisions.Web.Report rpt = new CrystalDecisions.Web.Report();
CrystalDecisions.CrystalReports.Engine.ReportDocument rpt1;

protected void Page_Load(object sender, EventArgs e)
{
SqlConnection myConnection = new SqlConnection(“Data Source=SWAMI\\SQLEXPRESS;Initial Catalog=gifts;Integrated Security=True”);

string str = “select * from order_master where userid=’HetaDave'”;

SqlDataAdapter da = new SqlDataAdapter(str,myConnection );
DataSet ds = new DataSet();
da.Fill(ds);
ds.WriteXml(Server.MapPath(“Report.xml”));

rpt.FileName = Server.MapPath(“CrystalReport.rpt”);
crdata.Report = rpt;

rpt1 = crdata.ReportDocument;

crp.ReportSource = rpt1;
crp.DataBind();

}
}

Advertisement