我正在使用水晶报表打印学生的学费明细,但我遇到了例外. [英] I am using crystal reports for printing the fees details of students but i am getting exception.

查看:72
本文介绍了我正在使用水晶报表打印学生的学费明细,但我遇到了例外.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我正在使用水晶报表打印学生的学费明细,但我遇到了例外.
例外是"Object reference not set to an instance of an object."

我的代码是:

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:

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();

推荐答案

该错误的最可能原因是您没有为crystalReportViewer1分配任何内容:
The most likely reason for that error is that you haven''t assigned anything to crystalReportViewer1:
CrystalReportViewer crystalReportViewer1 = new CrystalReportViewer();

或相似.

在行上放置一个断点:

Or similar.

Put a breakpoint on the line:

crystalReportViewer1.ReportSource = objRpt;

,您将看到它包含null


尝试替换此代码
try to replace this code
crystalReportViewer1.ReportSource = ds.Tables[0];           
crystalReportViewer1.Refresh();
ClsConnection.Conn.Close();.            


这篇关于我正在使用水晶报表打印学生的学费明细,但我遇到了例外.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆