1
votes

I have a problem in crystal reports the rep_doc.SetDataSource(ds.Tables[0]); has an error i don't know whats wrong with the code please help thanks in advance. The datable has values but its still showing null reference exception at CrystalReportViewer1.ReportSource = rep_doc; Please help thanks in advance. the first part is aspx.cs code and second is aspx code

public void noOfEvents()
{
     dtEvents = objAdmin.GetNoOfEvents();
     if (dtEvents != null)
     {
        //Report Code
        DataSet ds = new DataSet();
        ds.Tables.Add(dtEvents);
        ReportDocument rep_doc = new ReportDocument();
        rep_doc.Load(Server.MapPath("../Reports/Events.rpt"));
        rep_doc.SetDataSource(ds.Tables[0]);
        CrystalReportViewer1.ReportSource = rep_doc;
        CrystalReportViewer1.DataBind();
        CrystalReportViewer1.RefreshReport();
      }
}


<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" />

errors are as follows:

Line 42: rep_doc.SetDataSource(ds.Tables[0]);
Line 43:      
Line 44:CrystalReport1.ReportSource = rep_doc;
Line 45:CrystalReport1.DataBind();
Line 46:CrystalReport1.RefreshReport();



[NullReferenceException: Object reference not set to an instance of an object.]
   Assistvoter.Admin.Report.noOfEvents() in D:\ActiveProjects\Assist Voter\Assistvoter    \Admin\Report.aspx.cs:44
   Assistvoter.Admin.SuperAdmin.Button15_Click(Object sender, EventArgs e) in     D:\ActiveProjects\Assist Voter\Assistvoter\Admin\SuperAdmin.aspx.cs:95

System.Web.UI.WebControls.Button.OnClick(EventArgs e) +141 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +149 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +39 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +37 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +87 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4225

2
@Damith it is a simple thing i dono whats the error...Please helpJack
in error you have CrystalReport1 but in the code you have CrystalReportViewer1. what is correct?Damith
try by giving full path like rep_doc.Load("D:\ActiveProjects\Assist Voter\Assistvoter\Reports\Events.rpt");Damith
CrystalReport1 is correct i changed now thats it...Jack
Still the same result...:(Jack

2 Answers

0
votes

I guess your CrystalReportViewer1 is null. Put a code to check for null value to avoid using object's properties and methods if it is null.

0
votes

I had the same issue with this code reportDocument.SetDataSource(dataset);, I got the exception Object reference not set to an instance of an object. After hours trying everything I solved the issue by removing this

<dependentAssembly> <assemblyIdentity name="CrystalDecisions.ReportAppServer.DataSetConversion" publicKeyToken="692fbea5521e1304" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-13.0.3500.0" newVersion="13.0.3500.0" /> </dependentAssembly>

from the App.config and it worked. I hope this can help.