I am using TableAdapter method of dataset file to get data from database, and Crysral report object to create report instead of CrystalReport file itself. (Basically I don't want to use Physical CrystalReport File)
Here, sample of my Code
DataTable dtRpt = new DataTable();
CrystalReportViewer crv = new CrystalReportViewer();
using (uspRptComplainReceiptTableAdapter _adpSales = new uspRptComplainReceiptTableAdapter())
{
dtRpt = _adpSales.GetData(Convert.ToByte(bolObj.CompId), bolObj.ComplainId) as DataTable;
if (dtRpt != null && dtRpt.Rows.Count > 0)
{
crptComplainReceipt rpt1 = new crptComplainReceipt();
rpt1.SetDataSource(dtRpt);
crv.ReportSource = rpt1;
crv.PrintReport();
}
else
MessageBox.Show("Record not found.", "Report", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Now, I want to Export my report to Excel File using this method (CrystalReport Object). Please, help me for this problem...
Try This:
CrystalDecisions.CrystalReports.Engine.ReportClass rpt=new ReportClass();
rpt.ExportToDisk(ExportFormatType.Excel, "FilePath");
BTW do not forget to add the references.