24 June 2008

Using Crystal Report in ASP.NET

Yesterday I am looking for access crystal report by C#. This is step by step how to make report until display report by crystal report viewer.
1. Define element data using DataSet. Create new item -> DataSet. This is like XML format.Double click DataSet1.xsd and drag and drop DataTable. Define elemen data for report.
2. Create new crystal report file. Create using report wizard -> Create New Connection -> ADO.NET(XML) -> File path using DataSet1.xsd -> Next...next until finsih the process.
3. Now, ceate new web form. Drag and Drop the Crystal Report Viewer from toolbox.
4. How to bind ?

private void BindReport()
{
String VarSQL;
SqlDataAdapter VarRst;
DataSet ds = new DataSet();
CrystalDecisions.CrystalReports.Engine.ReportDocument oRpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

ClassDB.ClassToDB db = new ClassDB.ClassToDB();
VarSQL = "SELECT Cola,colb FROM tablename";
oRpt.Load(Server.MapPath("rpt/rpt_fuel.rpt"));
VarRst = db.ExecuteDataAdapter(VarSQL);
VarRst.Fill(ds, "report");


oRpt.SetDataSource(ds.Tables["report"]);
RptViewer.Visible = true;
RptViewer.ReportSource = oRpt;
RptViewer.DataBind();
}

Method ExecuteDataAdapter this is function from ClassDB the result is SqlDataAdapter.

I hope this step useful for your code.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home