set datasource from report(Start report event)
I load connections dynamically. I make sql command (select) on connaction in report (start report event) and i try set datasource from data after select.
Unfortunately get error:
FastReport.Utils.DataTableException: Data1: Table is not connected to the data. Register the data using Report.RegisterData method.
w FastReport.Data.TableDataSource.LoadData(ArrayList rows) w \WCFFastReport\ProjektFastRaportNET\FastRaport\FastReport Biblioteki\Data\TableDataSource.cs:wiersz 327
w FastReport.Data.DataSourceBase.LoadData() w \WCFFastReport\ProjektFastRaportNET\FastRaport\FastReport Biblioteki\Data\DataSourceBase.cs:wiersz 377
My code bellow:
How can register data?
Unfortunately get error:
FastReport.Utils.DataTableException: Data1: Table is not connected to the data. Register the data using Report.RegisterData method.
w FastReport.Data.TableDataSource.LoadData(ArrayList rows) w \WCFFastReport\ProjektFastRaportNET\FastRaport\FastReport Biblioteki\Data\TableDataSource.cs:wiersz 327
w FastReport.Data.DataSourceBase.LoadData() w \WCFFastReport\ProjektFastRaportNET\FastRaport\FastReport Biblioteki\Data\DataSourceBase.cs:wiersz 377
My code bellow:
      string sql = "select* from dokumenty where dok_id between 3000 and 4000";
      OdbcConnection con1 = new OdbcConnection(((Report)sender).Dictionary.Connections[0].ConnectionString);// connections load dynamically from externall application
      OdbcCommand cmd = new OdbcCommand(sql, con1);
      dt = new DataTable();
      dt.TableName = "Data1";
   Â
      using (OdbcDataAdapter ad = new OdbcDataAdapter(cmd))
      {
        ad.Fill(dt);
      }
      Text8.Text = dt.Rows.Count.ToString();
      tab = new TableDataSource();
   Â
      tab.Table = dt;
      tab.Name = "Data1";
      tab.Alias="Data1";
   Â
      Report.RegisterData(dt , "Data1");
      Report.GetDataSource("Data1").Enabled = true; Â
   Â
      Data1.DataSource = tab;
How can register data?
Comments
I get error when i set
Objects 'tab' and 'dt' are global object.
Where the problem is ?
in my case, when i click a button, execute this method :
assuming desktop application and already declared fastreport previewcontrol (internal FastReport.Preview.PreviewControl PreviewControl1;)
the question : who is reponsible to dispose fastreport class instance?
FastReport.Report report = new FastReport.Report();
if you click close button in fastreport previewcontrol, object report will be disposed.
never ever worry about memory leaks.
if you want to expose another report, create another instance :
FastReport.Report report = new FastReport.Report();
that's the answer about datasource not refreshing, create another instance of fastreport class.