We help IT Professionals succeed at work.

show crystal report in crystal report viewer on c# 2005 winform

ljhodgett
ljhodgett asked
on
Hi,

I have created a crystal report that is linked to a dataset. I am trying to find out how I would show this in a c# crystal report viewer contained in a winform. The code I usually use in vb.net is: -

Dim rpt As New crUsage_By_Date




        rpt.Load(Forms.Application.StartupPath & "\crUsage_By_Date.rpt")
        rpt.SetDataSource(DsReports1.Tables("Usage_By_Date"))

        rpt.SetParameterValue("Report_Period", DateTimePicker1.Text & " to " & DateTimePicker2.Text)
        rpt.SetParameterValue("Printed_By", MDIParent1.lblUser.Text)
        'frmPreviewReport.CrystalReportViewer1.ReportSource = rpt
        'frmPreviewReport.Show()

I am trying to find out the c# equivalent.

Many thanks
Lee
Comment
Watch Question

usually it is quiet the same but for few brackets changed ,,
try some msdn search
Senior Consultant
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2013
Commented:

Author

Commented:
Hi,

I've put the following code into my form:-

            CrystalDecisions.CrystalReports.Engine.ReportDocument crReportDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

            String path = Environment.CurrentDirectory;
            crReportDocument.Load(path + @"\crProgressReport.rpt");
            crReportDocument.SetDataSource(myDSMeasurements.Tables["dtMeasurements"]);
            crystalReportViewer1.ReportSource = crReportDocument;

but it comes up Load report failed on crReportDocument.Load(path + @"\crProgressReport.rpt"); the path variable seems to be correct and the rpt is contained within the directory. Unfortunately it doesn't give me any more information. What am I doing wrong please.

Many Thanks
Lee
Mike McCrackenSenior Consultant
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2013

Commented:
What is the purpose of the @ in the Load statement?

mlmcc
waiting for your reply

Author

Commented:
Hi,

For some reason it's not working on my development pc but it's ok on my laptop. I'm having quite a few issues with visual studio on my development pc so I think I need a fresh install.

Best regards
Lee

Explore More ContentExplore courses, solutions, and other research materials related to this topic.