水晶报表转换为流时出错?

fengjing888 2008-11-05 02:30:15
System.IO.Stream stream = Report.ExportToStream(ExportFormatType.PortableDocFormat);报错,提示未将对象引用设置到对象的实例.以前做的也是这么做的,没有出错,请高手指点,谢谢!
...全文
120 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
fengjing888 2008-11-05
  • 打赏
  • 举报
回复
报表显示为一个登陆窗口,提示The report you requested requires further information,请问是怎么回事?多谢!
fengjing888 2008-11-05
  • 打赏
  • 举报
回复
详细错误信息是这样的
InnerException = {"Logon failed.\nDetails: crdb_adoplus : Object reference not set to an instance of an object.\rError in File C:\\DOCUME~1\\ADMINI~1.SYB\\LOCALS~1\\Temp\\EmployeeProfile {9C847DBE-EAFC-4CAD-83F1-582D8207F6FD}.rpt:\nUnable to connect: incorrect log on parame...
阿泰 2008-11-05
  • 打赏
  • 举报
回复
界面上拖一个crystalreportsviewer控件

crystalReportViewer.ReportSource = Report;

放在
Report.SetDataSource(ds); 后面
fengjing888 2008-11-05
  • 打赏
  • 举报
回复
怎么加VIEWER让报表显示?
阿泰 2008-11-05
  • 打赏
  • 举报
回复
最好加个viewer显示下报表看看能不能正常显示,正常显示了才能正常输出。


另外
oa.fill(ds)的时候需要指定一个表名,就是你设计报表时的报名,比如这个可能是 Employee

那就是oa.fill(ds,"Employee")
fengjing888 2008-11-05
  • 打赏
  • 举报
回复
这是得到DS的代码:
string sqlEmp = "select ID,UserName as [Name],(select value from lookup where id=emp.lkup_jobtitle) JobTitle,(select value from lookup where id=emp.lkup_division) Division,(select value from lookup where id=emp.DepartmentID) Department,Hire_Date,Per_BirthDate,Manager,EM1_Contact,EM1_PhoneNo from employee emp where id= " + employeeID;

SqlDataAdapter da = new SqlDataAdapter(sqlEmp, conn);
DataSet ds = new DataSet();
da.Fill(ds);

if (ds.Tables[0].Rows.Count != 0) ds.Tables[0].TableName = "Employee"; else return null;

string sqlEdu = "select employee_NDX as ID,(select value from lookup where id=edu.LookupNDX_DEG) as Degree,Institution, DateCompleted,Comments from employee_education edu where employee_ndx= " + employeeID;

SqlDataAdapter eduda = new SqlDataAdapter(sqlEdu, conn);
DataSet eduds = new DataSet();
eduda.Fill(eduds);

if (eduds.Tables[0].Rows.Count != 0)
{
DataTable dtedu = new DataTable();
dtedu = eduds.Tables[0].Copy();
dtedu.TableName = "Employee_Education";
ds.Tables.Add(dtedu);
}


string sqlhis = "select employee_ndx ID, JobTitle, StartDate,EndDate, Department,WorkLocation,(select value from lookup where id=his.lookupndx_con) Country,(select value from lookup where id=his.lookupndx_chr) ChangeReason from employment_history his where employee_ndx= " + employeeID;

SqlDataAdapter hisda = new SqlDataAdapter(sqlhis, conn);
DataSet hisds = new DataSet();
hisda.Fill(hisds);

if (hisds.Tables[0].Rows.Count != 0)
{
DataTable dthis = new DataTable();
dthis = hisds.Tables[0].Copy();
dthis.TableName = "Employment_History";
ds.Tables.Add(dthis);
}

string sqlPhoto = "select Photo,ID from employee_photo where id= " + employeeID;
SqlDataAdapter Photoda = new SqlDataAdapter(sqlPhoto, conn);
DataSet Photods = new DataSet();
Photoda.Fill(Photods);

if (Photods.Tables[0].Rows.Count != 0)
{
DataTable dtPhoto = new DataTable();
dtPhoto = Photods.Tables[0].Copy();
dtPhoto.TableName = "Employee_Photo";
ds.Tables.Add(dtPhoto);
}

CrystalDecisions.CrystalReports.Engine.ReportDocument Report = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
string rptPath = HttpContext.Current.Server.MapPath("Report");
Report.Load(rptPath + "\\EmployeeProfile.rpt");
Report.SetDataSource(ds);
fengjing888 2008-11-05
  • 打赏
  • 举报
回复
XSD文件:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="EmployeeProfile" targetNamespace="http://tempuri.org/EmployeeProfile.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/EmployeeProfile.xsd" xmlns:mstns="http://tempuri.org/EmployeeProfile.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Employee">
<xs:complexType>
<xs:sequence>
<xs:element name="ID" type="xs:int" />
<xs:element name="Name" type="xs:string" />
<xs:element name="JobTitile" type="xs:string" />
<xs:element name="Division" type="xs:string" />
<xs:element name="Department" type="xs:string" />
<xs:element name="Hire_Date" type="xs:date" />
<xs:element name="Per_BirthDate" type="xs:date" />
<xs:element name="Manager" type="xs:string" />
<xs:element name="EM1_Contact" type="xs:string" />
<xs:element name="EM1_PhoneNo" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Employment_History">
<xs:complexType>
<xs:sequence>
<xs:element name="ID" type="xs:int" />
<xs:element name="JobTitle" type="xs:string" />
<xs:element name="StartDate" type="xs:date" />
<xs:element name="EndDate" type="xs:date" />
<xs:element name="Department" type="xs:string" />
<xs:element name="WorkLocation" type="xs:string" />
<xs:element name="Country" type="xs:string" />
<xs:element name="ChangeReason" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Employee_Photo">
<xs:complexType>
<xs:sequence>
<xs:element name="Photo" type="xs:base64Binary" />
<xs:element name="ID" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Employee_Education">
<xs:complexType>
<xs:sequence>
<xs:element name="ID" type="xs:int" />
<xs:element name="Degree" type="xs:string" />
<xs:element name="Institution" type="xs:string" />
<xs:element name="DateCompleted" type="xs:date" />
<xs:element name="Comments" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
fengjing888 2008-11-05
  • 打赏
  • 举报
回复
CrystalDecisions.CrystalReports.Engine.ReportDocument Report = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
string rptPath = HttpContext.Current.Server.MapPath("Report");
Report.Load(rptPath + "\\EmployeeProfile.rpt");
Report.SetDataSource(ds);


System.IO.Stream stream = Report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);

上面几句都没问题,但到了这句就报错了,DS里也有值,真的不知道是哪出问题了,
阿泰 2008-11-05
  • 打赏
  • 举报
回复
测试了一下,可以的
看一下Report此时的状态是否正常。

4,818

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 图表区
社区管理员
  • 图表区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧