2015-08-17 55 views
1

我只是學習者一點點如何使用CR今天,創造了用它稱爲Report1.rpt的報告。 該報告使用三個過程(稱爲Get_Query1,Get_Query2和Get_Query3)連接到我的數據庫。創建Crystal報表使用C#

在我的表單應用程序已經創建使用C#,我有所謂的按鈕保存爲PDF,將傳遞一個值x過程中的參數,然後打開報表,加載所需要的參數。

的代碼如下:

private void savepdfToolStripMenuItem_Click(object sender, EventArgs e) 
{ 
    //IN THIS PART WE GET THE FORM ID, AND SEND IT TO THE PROCEDURE PARAMETER 
    int x = ID_FORM; 
    if (x == 0) 
     x = Get_Form_ID(); 
    MessageBox.Show(Convert.ToString(x)); 
    cmd = new SqlCommand("Get_Query_1", sc); 
    cmd.CommandType = CommandType.StoredProcedure; 
    cmd.Parameters.Add(new SqlParameter("@MoM_ID", 339)); 

    //THE NEXT STEPS 

     ReportDocument reportDocument = new ReportDocument(); 
     string filePath = @"C:\Users\nbousaba\Documents\Visual Studio 2013\Projects\WindowsFormsApplication4\WindowsFormsApplication4\Report1"; 
     reportDocument.Load(filePath); 
     CrystalReportViewer crv = new CrystalReportViewer(); 
     crv.ReportSource = reportDocument; 


} 

的問題,到目前爲止,當我運行的代碼,我得到一個異常錯誤:

An unhandled exception of type 'System.TypeInitializationException' occurred in WindowsFormsApplication4.exe

Additional information: The type initializer for 'CrystalDecisions.CrystalReports.Engine.ReportDocument' threw an exception.

我已經試過,我發現不同的代碼在線,他們都導致同樣的問題。

我還使用了下面的包

using CrystalDecisions.CrystalReports.Engine; 
using CrystalDecisions.ReportSource; 
using CrystalDecisions.Shared; 
using CrystalDecisions.Windows.Forms; 

是在我的代碼的問題?

回答

1

事實證明,即使在下載軟件包後,如果您使用Visual Studio 2013,CR將無法正常,直到你現在安裝以下

http://scn.sap.com/docs/DOC-7824 

所有工作正常運行。