Passing dataset at runtime to FastReport.Core , C#

edited February 2022 in FastReport .NET

I am using FastReport.Core 2022.1.5 nuget package in a .NET 5.0 Forms application. I have used FR Designer to generate a frx file, and I supply the data using RegisterData() at runtime. But when the Prepare is called, it throws an exception that "table is not connected to data". The data source name in frx is exactly matching the name passed to the RegisterData method.

Let me know what is missing here ?

The code flow is as below,

  FillTheDataset(); //queries using Npgsql, a postgresql db and gets back records filled in a DataSet

      Report report = new Report();

      report.Load(@"localPgReport1.frx");

      //register the dataset

      _dataSet.Tables[0].TableName = "dept";

      report.RegisterData(_dataSet,"departments");

      report.GetDataSource("departments").Enabled = true;

      //prepare the report

      report.FileName = "My Postgres Report";

      report.Prepare(); //exception in this line


FRX snippet,

<TableDataSource Name="departments" ReferenceName="departments" Enabled="true" TableName="dept">

...<DataBand Name="Data1" DataSource="departments">

.. <TableCell Name="Cell21" Text="[dept.dept_id]" Font="Arial, 10pt"/>

Comments

  • Changing the TableDataSource element inside the frx file to

    <TableDataSource Name="dept" ReferenceName="departments.dept" Enabled="true" TableName="dept"> and

    <DataBand Name="Data1" DataSource="dept">, worked fine.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.