Cris Seiner

Cris Seiner

  • NA
  • 1
  • 0

ReportViewer problem

May 3 2007 12:58 PM

I have a form with button, click in button and opened reportViewer - first run is good, but when i click once again in button and when ReportViewer is opened - my program is crasched.

PLEASE HELP ME!

code: 

[c#]
using System;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Data.OleDb;

class PeriodReportList2 : Form
{
    #region Fields
    //
    Microsoft.Reporting.WinForms.ReportViewer reportViewer = new Microsoft.Reporting.WinForms.ReportViewer();
    Microsoft.Reporting.WinForms.ReportDataSource reportDataSource = new Microsoft.Reporting.WinForms.ReportDataSource();
    //
    #endregion

    public PeriodReportList2()
    {
        this.reportViewer.Parent = this;
        this.reportViewer.Dock = DockStyle.Fill;
        this.reportViewer.Reset();
        this.reportViewer.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local;
        this.reportViewer.LocalReport.DataSources.Add(reportDataSource);
        // Set RDL file.
        this.reportViewer.LocalReport.ReportEmbeddedResource = "ClientRecords.Report1.rdlc";
        //
        fill();
        //
        // Form --------------------------------------------------------------
        //
        this.Text = "Report (" + dateBegin + " - " + dateEnd + ")";
        this.Icon = new Icon(this.GetType(), "ClientRecords.Icon.ico");
        this.ClientSize = new Size(605, 200);
        this.CenterToScreen();
        this.ShowInTaskbar = true;
    }

    //
    // ======================================================================
    //

    // ******************************************
    // fill
    // ******************************************
    void fill()
    {
        OleDbDataAdapter dataAdapter = new OleDbDataAdapter();
        DataTable dataTable = new DataTable();
        OleDbCommand cmd;


        cmd = new OleDbCommand("SELECT ....", Common.connection.returnConnection());

        try
        {
            Common.connection.open();

            dataAdapter.SelectCommand = cmd;
            OleDbCommandBuilder cmdBuilder = new OleDbCommandBuilder(dataAdapter);

            dataTable.Clear();
            dataAdapter.Fill(dataTable);
            //
            // Supply a DataTable corresponding to each report dataset.
            this.reportDataSource.Name = "DataSet1_DataTable1";
            this.reportDataSource.Value = dataTable;
            //
            reportViewer.RefreshReport();
        }
        catch { }
        finally { Common.connection.close(); }
    }
}
[/c#]


 -------------- This code I run as:
[c#]
PeriodReportList2 prl = new PeriodReportList2();
prl.Show();
[/c#]