http://www.csdn.net/expert/topic/962/962116.xml?temp=.7566034

解决方案 »

  1.   

    llllay() 
      怎么修改?
      

  2.   

    你在导出到XLS时.报表的对象是否还在?一般情况在用户需要时才导出.这时显示的报表对象已经销毁了.你可以在导出以前重新生成一个报表对象试试.
      

  3.   

    我确实重新生成了,你帮我看看
    private void Button1_Click(object sender, System.EventArgs e)
    {
    ClReport_ds MyReport = new ClReport_ds();         CrystalDecisions.Shared.DiskFileDestinationOptions DiskOpt = new CrystalDecisions.Shared.DiskFileDestinationOptions(); MyReport.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;

    MyReport.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.Excel;

    DiskOpt.DiskFileName = "f:\\程序\\net\\MyWeb\\out.xls";

    MyReport.ExportOptions.DestinationOptions = DiskOpt;

    MyReport.Export();
    }提示MyReport.Export();出错
      

  4.   

    http://www.csdn.net/expert/topic/939/939228.xml?temp=.2322199
      

  5.   

    总结了一下:
    如果数据库密码为空的话(我的测试是user id=sa;pwd=)可以直接使用下面代码:
    CrystalReportViewer1.ReportSource = Server.MapPath("CrystalReport1.rpt");
    CrystalReportViewer1.DataBind();如果数据库密码不为空的话,则应该添加以下代码安全登陆:ReportDocument Report = new ReportDocument();
    Report.Load(Server.MapPath("CrystalReport1.rpt"));
    TableLogOnInfo logOnInfo = new TableLogOnInfo();//对报表中的每个表进行循环
    for(int i=0;i==Report.DataBase.Tables.Count-1;i++)
    {
       logOnInfo.ConnectionInfo.UserId = "sa";
       logOnInfo.ConnectionInfo.Password = "yourpassword";
       Report.DataBase.Tables[i].ApplyLogOnInfo(logOnInfo);
    }
    CrystalReportViewer1.ReportSource = Report;
    CrystalReportViewer1.DataBind();
    //当然如果密码为空的话也同样可以使用这种方法的以上代码需要
    using CrystalDecisions.CrystalReports.Engine;
    using CrystalDecisions.Shared;