ASP.Net Crystal Report Error: Object reference not set to an instance of an object

Last Reply 13 days ago By Mudassar

Posted 14 days ago

this code gives me error Object reference not set to an instance of an object

using (ReportDocument report = new ReportDocument())
{
    report.Load(Server.MapPath("~/Crystal Reports/CrReport10.rpt"));
    ViewState["dtgrid"] = dt_grid;
    report.SetDataSource(dt_grid);
    crvCMSettleBill.RefreshReport();
    crvCMSettleBill.ReportSource = report;
    crvCMSettleBill.ReuseParameterValuesOnRefresh = true;
}

But report works fine when coding like this without using using statement.

ReportDocument report = new ReportDocument();
report.Load(Server.MapPath("~/Crystal Reports/CrReport10.rpt"));
ViewState["dtgrid"] = dt_grid;
report.SetDataSource(dt_grid);
crvCMSettleBill.RefreshReport();
crvCMSettleBill.ReportSource = report;
crvCMSettleBill.ReuseParameterValuesOnRefresh = true;

please help me sort out this issue..

thanks regards

Posted 13 days ago

Simply dispose the object instead of using USING.

report.Dispose();