This is a migrated thread and some comments may be shown as answers.

ReportViewer errors after first view

2 Answers 93 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Digital Man
Top achievements
Rank 2
Digital Man asked on 09 Oct 2008, 11:08 AM
I have a windows form with the ReportViewer control on it which I re-use to show various reports. I also have properties on that form to set the report parameters. The first time I show a report with the form it works fine. But for some reason after that I get conversion errors with what seems to be the passing of the report parameters. It's as if it's not closing down the form fully or something.

The start of my form code is like this (I pass in the report I want to view):

    public partial class ReportTester : Form
    {
        public ReportTester(Telerik.Reporting.Report Report)
        {
            InitializeComponent();

            reportViewer1.Report = Report;
            reportViewer1.RefreshReport();
        }

        public int UserId
        {
            set { reportViewer1.Report.ReportParameters["UserID"].Value = value; }
        }
...

And then in my main form I launch reports like this:

                    ReportTester report;
                    if (type == ReportTypeEnum.Regular)
                    {
                        report = new ReportTester(new BPReports.Report1());
                    }
                    else
                    {
                        report = new ReportTester(new BPReports.Report2());
                    }

                   report.UserId = _currUser;
                   report.ShowDialog();
....

But the second time I show a report even if it's the same report I get an error in the viewer about not being able to convert int to string or string to datetime.

Any ideas?

2 Answers, 1 is accepted

Sort by
0
Digital Man
Top achievements
Rank 2
answered on 09 Oct 2008, 11:43 AM
Ok, solved my own problem. I was calling the report's refresh method in the form's constructor which would happen before the report parameters were set. Not sure why it always works on the first run but moving it to a separate method call fixed it.
0
Steve
Telerik team
answered on 09 Oct 2008, 11:49 AM
Hello Dan,

As noted in our documentation and appearing in the intellisense for the RefreshReport() method - This method should not be called before the Form.Load() event is fired (avoid using it in the Form's constructor).

Kind regards,
Steve
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
General Discussions
Asked by
Digital Man
Top achievements
Rank 2
Answers by
Digital Man
Top achievements
Rank 2
Steve
Telerik team
Share this question
or