使用C#创建Crystal报表

时间:2015-08-17 10:57:51

标签: c# pdf crystal-reports

我今天学习了一些如何使用CR并使用它创建了一个名为Report1.rpt的报告。 该报告使用三个过程连接到我的数据库,名为Get_Query1,Get_Query2和Get_Query3。

在我使用C#创建的表单应用程序中,我有一个名为save to 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;


}

到目前为止的问题,当我运行代码时,我收到一个异常错误:

  

未处理的类型' System.TypeInitializationException'   发生在WindowsFormsApplication4.exe

中      

附加信息:类型初始化程序   ' CrystalDecisions.CrystalReports.Engine.ReportDocument'扔了一个   异常。

我尝试过在网上找到的不同代码,但它们都导致了同样的问题。

我还使用了以下软件包

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

我的代码中存在问题吗?

1 个答案:

答案 0 :(得分:1)

事实证明,即使在下载软件包之后,如果您使用的是visual studio 2013,在安装以下内容之前CR将无法正常运行

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

现在一切正常。