Using Crystal Reports ReportDocument

I recently started using the latest version of Crystal Reports with Visual Studio 2010 and SharpDevelop in a Windows application with forms (forms). I downloaded the latest Crystal DLLs for Visual Studio 2010 from SAP and manually created the links to the following

using CrystalDecisions.CrystalReports; using CrystalDecisions.CrystalReports.Engine; using CrystalDecisions.ReportSource; 

Then I create a ReportDocument to open the rpt file:

 ReportDocument rptDoc = new ReportDocument(); 

it all compiles fine. The problem occurs when I try to use the rtpDoc object for something;

 rptDoc.Load(@"c:\DialLeadsByDistributor.rpt"); 

it is as if the compiler did not understand it as an object of a class, despite the fact that when you mouse over a variable, it correctly describes it as CrystalDecisions.CrystalReports.Engine.ReportDocument , but not only intellisense does not show me any methods or properties of the object, I get the following compiler error, which puzzled me:

Invalid token '(' in a member declaration of a class, structure, or interface

which refers to the above statement as a violation string ...

Can anyone shed some light on this? If I look at the metadata for the ReportDocument class, it contains three Load methods, the first of which takes a string that represents the path to the rpt file. The fact that this problem occurs both in Visual Studio 2010 and in SharpDevelop is at least consistent, but it still makes no sense to me.

+4
source share
2 answers

try this code ... it works in both VS2010 and 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; } } 

}

0
source

Try to get rid of the @ sign. I am currently creating a program around the same idea, and I have not included this sign and there are no problems.

-one
source

Source: https://habr.com/ru/post/1396516/


All Articles