Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello there ,

I am using crystal reports for printing the fees details of students but i am getting exception.
Exception is "Object reference not set to an instance of an object."

My code is:
C#
public Payreport(int studid) //studid is the student id which admin is selecting
        {
           
            this.studid = studid;
            
            ClsConnection.Conn.Open();
            string sql = "SELECT ADD_Master.FName, ADD_Master.MName, ADD_Master.LName, tbinst_details.inst_id, tbinst_details.inst_amt, tbinst_details.note,tbinst_details.inst_date, tbinst_details.inst_type FROM tbinst_details INNER JOIN ADD_Master ON ADD_Master.ADD_No = tbinst_details.stu_id where stu_id= '" + studid + "'";
            SqlDataAdapter dscmd = new SqlDataAdapter(sql, ClsConnection.Conn);
            DataSet ds = new DataSet();
            //DataSet ds = new DataSet();
            dscmd.Fill(ds);
           
            

            Pay objRpt = new Pay();
            objRpt.SetDataSource(ds.Tables[0]);
            crystalReportViewer1.ReportSource = objRpt;//getting exception here. 
            crystalReportViewer1.Refresh();
            ClsConnection.Conn.Close();
Posted
Updated 6-Feb-12 21:23pm
v3
Comments
thatraja 7-Feb-12 3:22am    
Error on which line? Debug & see the values.
SantoshRohinSantosh 7-Feb-12 3:24am    
Ya I debug values are coming right but still I am getting exception.
OriginalGriff 7-Feb-12 3:22am    
Which line is it excepting on?
zyck 7-Feb-12 3:26am    
does objRpt has value?

try to debug if objRpt is not empty
SantoshRohinSantosh 7-Feb-12 3:31am    
Ya it have value.

The most likely reason for that error is that you haven't assigned anything to crystalReportViewer1:
C#
CrystalReportViewer crystalReportViewer1 = new CrystalReportViewer();
Or similar.

Put a breakpoint on the line:
C#
crystalReportViewer1.ReportSource = objRpt;
And you will see that it contains null
 
Share this answer
 
try to replace this code
HTML
crystalReportViewer1.ReportSource = ds.Tables[0];           
crystalReportViewer1.Refresh();
ClsConnection.Conn.Close();.            
 
Share this answer
 
v3

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