2012-05-05 66 views
0

我是使用Visual Studio 10的SAP Crystal Reports中的新功能。我使用具有三個參數的存儲過程在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"); 

    } 

回答

0
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.