0

我是使用 Visual Studio 10 的 SAP Crystal Reports 新手。我使用具有三个参数的存储过程在 SAP Crystal Reports 中生成了一个报表。报告加载良好,但是当我尝试打印并导出它时,会显示以下错误。

使用您指定的选项导出失败。请检查您的选项,然后重试。

我还尝试在控件属性上硬键入 ReportSource,但随后会显示登录信息,我需要提供用户名和密码。我想避免这种情况。这是我的代码:

private void loadreport(DateTime dt1, DateTime dt2, int cd)
    {
        ReportDocument reportDocument = new ReportDocument();

        ParameterField paramField = new ParameterField();
        ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();
        ParameterFields paramFields = new ParameterFields();




        //Set instances for input parameter 1 -  @Dept

        paramField.Name = "@date1";

        //*Remember to reconstruct the paramDiscreteValue and paramField objects

        paramDiscreteValue.Value = dt1;

        paramField.CurrentValues.Add(paramDiscreteValue);

        //Add the paramField to paramFields

        paramFields.Add(paramField);

        ParameterField paramField2 = new ParameterField();
        ParameterDiscreteValue paramDiscreteValue2 = new ParameterDiscreteValue();

        paramField2.Name = "@date2";
        paramDiscreteValue2.Value = dt2;
        paramField2.CurrentValues.Add(paramDiscreteValue2);
        paramFields.Add(paramField2);


        ParameterField paramField3 = new ParameterField();
        ParameterDiscreteValue paramDiscreteValue3 = new ParameterDiscreteValue();

        paramField3.Name = "@cid";
        paramDiscreteValue3.Value = cd;
        paramField3.CurrentValues.Add(paramDiscreteValue3);
        paramFields.Add(paramField3);


        CrystalReportViewer1.ParameterFieldInfo = paramFields;
        reportDocument.Load(Server.MapPath("testreport.rpt"));
        //Load the report by setting the report source

        CrystalReportViewer1.ReportSource = reportDocument;
        CrystalReportViewer1.DisplayGroupTree = false;
        //set the database loggon information.




        reportDocument.SetDatabaseLogon("sa", "12345", @".\SQLEXPRESS", "AnivetERP");

    }
4

1 回答 1

-1
    It maybe is because of the post back to make the report disappear. 
    You maybe can store the report into the session. and run it in the post back.

    if(Page.IsPostBack)
    {
    if(session['report'] != null)
{
                this.CrystalReportViewer1.ReportSource = session['report'] as CrystalDecisions.CrystalReports.Engine.ReportDocument;
                this.CrystalReportViewer1.DataBind();
}
    }

    Hope it can help you.
于 2012-06-12T11:36:36.323 回答