[英]Creating Crystal report Using C#
I just learner a little how to use CR today and created a report called Report1.rpt using it. 我今天只是学习了一些如何使用CR的知识,并使用它创建了一个名为Report1.rpt的报告。 The report is connected to my database using three procedures, called Get_Query1, Get_Query2 and Get_Query3. 该报告使用三个过程Get_Query1,Get_Query2和Get_Query3连接到我的数据库。
In my form application already created using C#, i have button called save to pdf, that will pass a value x to the parameters in the procedure, and then open the report, loading the parameter needed. 在已经使用C#创建的表单应用程序中,我有一个名为save to pdf的按钮,它将把x值传递给过程中的参数,然后打开报表,加载所需的参数。
The code is the following: 代码如下:
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;
}
The problem so far, that when i run the code, i get an exception error: 到目前为止的问题是,当我运行代码时,出现异常错误:
An unhandled exception of type 'System.TypeInitializationException' occurred in WindowsFormsApplication4.exe WindowsFormsApplication4.exe中发生了类型为'System.TypeInitializationException'的未处理异常
Additional information: The type initializer for 'CrystalDecisions.CrystalReports.Engine.ReportDocument' threw an exception. 附加信息:'CrystalDecisions.CrystalReports.Engine.ReportDocument'的类型初始值设定项引发了异常。
I have tried different codes that i found online, and they are all leading to the same problem. 我尝试了在网上找到的不同代码,它们都导致相同的问题。
I also used the following packages 我还使用了以下软件包
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.ReportSource;
using CrystalDecisions.Shared;
using CrystalDecisions.Windows.Forms;
Is the problem in my code ? 这是我的代码中的问题吗?
It turns out that even after downloading the packages, if you are using visual studio 2013, CR will not function properly until you install the following 事实证明,即使下载了软件包,如果您使用的是Visual Studio 2013,CR也将无法正常运行,除非您安装以下组件
http://scn.sap.com/docs/DOC-7824
All is working fine now. 现在一切正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.