C# 使用水晶报表 ReportDocument
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9285114/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
using Crystal Reports ReportDocument
提问by Gary
I recently started using the latest version of Crystal Reports with both Visual Studio 2010 and SharpDevelop in a c# windows application (forms). I've downloaded the latest Crystal DLLs for Visual Studio 2010 from SAP and manually created references to the following
我最近开始在 ac# windows 应用程序(表单)中使用最新版本的 Crystal Reports 和 Visual Studio 2010 和 SharpDevelop。我已经从 SAP 下载了 Visual Studio 2010 的最新 Crystal DLL,并手动创建了对以下内容的引用
using CrystalDecisions.CrystalReports;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.ReportSource;
I then create a ReportDocument so that I can open a rpt file:
然后我创建一个 ReportDocument 以便我可以打开一个 rpt 文件:
ReportDocument rptDoc = new ReportDocument();
this all compiles fine. The problem arises when I try to use the rtpDoc object to do anything;
这一切都编译得很好。当我尝试使用 rtpDoc 对象做任何事情时,问题就出现了;
rptDoc.Load(@"c:\DialLeadsByDistributor.rpt");
it's as if the compiler doesn't realize it's a class object, despite the fact that when I mouse over the variable it reports it properly as a CrystalDecisions.CrystalReports.Engine.ReportDocument, but not only does intellisense not show me any methods or properties of the object, I get the following compiler error which has me stumped:
就好像编译器没有意识到它是一个类对象,尽管事实上当我将鼠标悬停在变量上时,它会将其正确报告为 a CrystalDecisions.CrystalReports.Engine.ReportDocument,但智能感知不仅没有向我显示该对象的任何方法或属性,我得到以下编译器错误让我难倒:
Invalid token '(' in class, struct, or interface member declaration
类、结构或接口成员声明中的无效标记“(”
which references the above statement as the offending line...
将上述语句引用为违规行...
Can anyone shed any light on this? If I look at the metadata for the ReportDocument class is does contain three Load methods, the first of which takes a string which is the rpt file path. The fact that this problem occurs in both Visual Studio 2010 and SharpDevelop is at least consistent, but still makes no sense to me.
任何人都可以对此有所了解吗?如果我查看 ReportDocument 类的元数据,它确实包含三个 Load 方法,第一个方法采用一个字符串,它是 rpt 文件路径。这个问题在 Visual Studio 2010 和 SharpDevelop 中都发生的事实至少是一致的,但对我来说仍然没有意义。
回答by Tom Holbrook
Try getting rid of the @ sign. I'm currently building a program around this same idea, and I have not included this sign and there are no issues.
尝试摆脱@ 符号。我目前正在围绕同样的想法构建一个程序,我没有包含这个标志,也没有问题。
回答by user1943915
try this code...it works both in VS2010 and sharpdevelop4:
试试这个代码……它在 VS2010 和sharpdevelop4 中都有效:
using System;
using System.Drawing;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.ReportSource;
using CrystalDecisions.Windows.Forms;
namespace myapp
{
public partial class tstfrm1 : Form
{
public tstfrm1()
{
InitializeComponent();
ReportDocument rptDoc = new ReportDocument();
rptDoc.Load(@"C:\CrystalReport1.rpt");
/*If you have a datasource, link it like below*/
//rptDoc.SetDataSource(dataset.Tables["tripsheet"]);
CrystalReportViewer crystalReportViewer1 = new CrystalReportViewer();
crystalReportViewer1.ReportSource = rptDoc;
crystalReportViewer1.Refresh();
this.Controls.Add(crystalReportViewer1);
crystalReportViewer1.Dock = DockStyle.Fill;
}
}
}
}

