views:

22

answers:

1

I am trying to load a crystal report which is supposed to load a report according to the date chosen by the user. I have written the code below to help me implement this but when I choose the date using a datetimepicker (dtpDate) an click the load button (btnReport) the compiler throws an exception that it cannot load the report. Can u please help me find where the error is? and how can i correct it?

namespace linqToSql_trial
{
    public partial class frmFlightDetailsReport : Form
    {
        public frmFlightDetailsReport()
        {
            InitializeComponent();
        }

        private void btnReport_Click(object sender, EventArgs e)
        {
            ReportDocument cryRpt = new ReportDocument();
            cryRpt.Load("C:\\Users\\Daniel\\Desktop\\linqToSql_trial\\linqToSql_trial\flightDetailsReport.rpt");

            ParameterFieldDefinitions crParameterFieldDefinitions ;
            ParameterFieldDefinition crParameterFieldDefinition ;
            ParameterValues crParameterValues = new ParameterValues();
            ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();

            crParameterDiscreteValue.Value = dtpDate.Value;
            crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
            crParameterFieldDefinition = crParameterFieldDefinitions["flightdate"];
            crParameterValues = crParameterFieldDefinition.CurrentValues;

            crParameterValues.Clear();
            crParameterValues.Add(crParameterDiscreteValue);
            crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

            crystalReportViewer1.ReportSource = cryRpt;
            crystalReportViewer1.Refresh(); 

        }

        private void frmFlightDetailsReport_Load(object sender, EventArgs e)
        {

        }
    }
}
A: 

I have adjusted the cryRpt.Load line to this

cryRpt.Load(@"C:\Users\Daniel\Desktop\linqToSql_trial\linqToSql_trial\flightDetailsReport.rpt");

and it has managed to load.

Allan