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
CrystalReport1
but in the code you haveCrystalReportViewer1
. what is correct? – Damithrep_doc.Load("D:\ActiveProjects\Assist Voter\Assistvoter\Reports\Events.rpt");
– Damith