Assign list data to report problem
I try to use designer to create report, as need to debug purpose, from the report will connect my mssql database to get fields and column, so the report.frx will be like
<MsSqlDataConnection Name="Datasource" ConnectionString="....">
<TableDataSource Name="Table" Alias="BS" DataType="System.Int32" Enabled="true" SelectCommand="select * from [dbo].[fn_glBSReport] ('2023-3-31','2022-4-1')">
<Column Name="Id" DataType="System.Int32"/>
<Column Name="AccountTypeId" DataType="System.Int32"/>
<Column Name="AccountType" DataType="System.String"/>
<Column Name="AccountCode" DataType="System.String"/>
<Column Name="BalanceAmt" DataType="System.Decimal"/>
</TableDataSource>
</MsSqlDataConnection>
In the dotnet, for load this report, I don't need to pass sql connection to this report, just use report.load(dataObjects, "BS");
from frx I remove <MsSqlDataConnection Name="Datasource" ConnectionString="...."> </MsSqlDataConnection>
but finally , it's throw the exception which said
FastReport.Utils.DataTableException: BS: Table is not connected to the data. Register the data using Report.RegisterData method.
at FastReport.Data.TableDataSource.LoadData(ArrayList rows)
at FastReport.Data.DataSourceBase.LoadData()
at FastReport.Data.DataSourceBase.Init(Relation relation, String filter, SortCollection sort, Boolean useAllParentRows)
at FastReport.Data.DataSourceBase.Init(DataSourceBase parentData, String filter, SortCollection sort, Boolean useAllParentRows)
for this case, how to handle it ?
Comments
Hello!
The DataTableException: ‘Table is not connected to the data’ occurs because simply removing the <MsSqlDataConnection> tag leaves a TableDataSource object within the .frx file with Name="Table", Alias="BS" and a reference to a non-existent connection, instead of a source with ReferenceName="Data.BS".
The simplest and most reliable approach is not to edit the XML manually, but to switch the source programmatically immediately after Load():