本文介绍了使用Linq to Sql的Crystal Reports的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我将代码修改为:.FirstorDefault();.到ToList();

现在我得到了:
Quote:
System.NullReferenceException:对象引用未设置为对象的实例.



rptStudyCertificate rsc = new rptStudyCertificate();
使用(DataClasseDataContext db = new DataClasseDataContext())
{
var list =(来自db.StudyCertificates中的数据
将db.StudentClassDetails中的clsdet加入data.AdmissionNo等于clsdet.AdmissionNo
其中data.ID == Convert.ToInt16(sno)
选择新的{ID = data.ID,Class = clsdet.Class,AcademicYear = clsdet.AcademicYear,AdmissionNo = clsdet.AdmissionNo,Conduct = data.Conduct}).ToList();


如果(list!= null)
{
rsc.SetDataSource(list);
CrystalReportViewer1.ReportSource = rsc;
}
}



在此先感谢...................

Now i modified the code as: .FirstorDefault(); to ToList();

Now I got :
Quote:
System.NullReferenceException: Object reference not set to an instance of an object.



rptStudyCertificate rsc = new rptStudyCertificate();
using (DataClasseDataContext db = new DataClasseDataContext())
{
var list = (from data in db.StudyCertificates
join clsdet in db.StudentClassDetails on data.AdmissionNo equals clsdet.AdmissionNo
where data.ID == Convert.ToInt16(sno)
select new { ID = data.ID, Class = clsdet.Class, AcademicYear = clsdet.AcademicYear, AdmissionNo = clsdet.AdmissionNo, Conduct = data.Conduct}).ToList();


if (list != null)
{
rsc.SetDataSource(list);
CrystalReportViewer1.ReportSource = rsc;
}
}



Thanks in advance...................

推荐答案

rptStudyCertificate rsc = new rptStudyCertificate();

//This is the instantiation that Ahmed suggested.  You can do this here or earlier
CrystalReportViewer1 = new CrystalReportViewer();

using (DataClasseDataContext db = new DataClasseDataContext())
{
   var list = (from data in db.StudyCertificates
   join clsdet in db.StudentClassDetails on data.AdmissionNo equals clsdet.AdmissionNo
   where data.ID == Convert.ToInt16(sno)
   select new { ID = data.ID, Class = clsdet.Class, AcademicYear =
   clsdet.AcademicYear, AdmissionNo =
   clsdet.AdmissionNo, Conduct = data.Conduct}).ToList();


  if (list != null)
  {
    rsc.SetDataSource(list);
    CrystalReportViewer1.ReportSource = rsc;
  }
}


这篇关于使用Linq to Sql的Crystal Reports的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 21:43