Click here to Skip to main content
15,901,205 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Im making crystal report in VS 2008,And want to add a subreport,I have written following commands


1)CrystalReport1 cr = new CrystalReport1();
2) DataSet ds = new DataSet();
3) ds.Tables.Add("table");
4) ds.Tables[0].Columns.Add("name");
5) ds.Tables[0].Rows.Add("fksdfs");
6)cr.OpenSubreport("CrystalReport1.rpt").SetDataSource(ds.Tables["table"]);
7)crystalReportViewer1.ReportSource = cr;

getting error in 6th line : "Object reference not set to an instance of an object"

I have no clue how to resolve!!Can anyone plz help!!its urgent!!
Posted

1 solution

Object reference not set to an instance of an object
This error simply means that some object value is null and yet you are trying to use it somewhere directly or using it's properties.

Using DEBUGGER can tell you the exact object. When you got this error, you already know the line (which you have not mentioned here). Even if you are not aware, a simple debugging would tell you that.

Now here,
most probably the error is in line:
C#
cr.OpenSubreport("CrystalReport1.rpt").SetDataSource(ds.Tables["table"]);


You are trying to open a subreport using a method 'OpenSubreport' but you have no where defined that the crystal report object 'cr' has one.

Read on how to add subreports dynamically through code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900