Pages

Monday, October 19, 2009

Steps to Create a Crystal Report based on an XML schema (XSD) file.

1.Create Dataset with.(e.g Select * from anytable)
Note:-Basic knowledge of C# required
2.e.g Dataset ds;
3.Then write the following code e.g ds.WriteXmlSchema("RptDailyAll.xsd");
4.Above code will genrate "RptDailyAll.xsd" file in the current directory
5.Now open a new crystall report and follow the steps as seen in images














6.Now write the following code
 try
  {
  //This (frmReportViewer) //is form where we have to add Report viewer
  //here >>>we named it>> CrptView

  frmReportViewer frm = new frmReportViewer();

  frm.MdiParent = this.MdiParent;
  frm.Show();
  frm.CrptView.DisplayGroupTree = false;
  frm.RptDailyAll(ds);//explaned in step:-7
  }
 catch (Exception ex)
  {
  MessageBox.Show(ex.Message);
  }
 ds.Dispose();

7.Now this the function we have to add it in
frmReportViewer form as seen above

 public void RptDailyAll(DataSet d1)
  {
  ReportDocument rptDoc = new ReportDocument();
  rptDoc.Load(Application.StartupPath.Replace("bin\\Debug", "") + @"\\Reports\\rptDailyAll.rpt");
  rptDoc.SetDataSource(d1);
  CrptView.ReportSource = rptDoc;
  }

No comments: