DataTable 作为 FastReport 的源

问题描述

我有一个可用的 FastReport .frx 文件,Visual Studio 2019 ASP.NET Web 应用程序使用 .Net Core 2.2(我知道,但被要求)。
原始 sql 没有参数,正常工作,我可以输出一个 pdf 文件
鉴于我有一个OData端点并且WHERE条件可能很复杂,因此不容易提供sql参数,最好的解决方案是提供一个与原始报表sql源相同字段的DataTable ,这是我多年来在 Crystal Reports 中所做的事情。
.frx文件中定义为:

<Dictionary>
<MssqlDataConnection Name="Connection" ConnectionString="rijcmlqH...">
  <TableDataSource Name="Table1" DataType="system.int32" Enabled="true" SelectCommand="SELECT ...">
    <Column Name="GUID" DataType="System.String"/>
    <Column Name="Position" DataType="System.String"/>
    <Column Name="Code" DataType="System.String"/>
    <Column Name="Name" DataType="System.String"/>
  </TableDataSource>
</MssqlDataConnection>
</Dictionary>

以及我对控制器的最新尝试:

string strRptPath = Path.Combine(objHostEnv.ContentRootPath,"reports\\Test.frx");
var webReport = new WebReport();

var mssqlDataConnection = new MssqlDataConnection();
mssqlDataConnection.ConnectionString = "sqlservervalidconnstring";
Registeredobjects.AddConnection(typeof(MssqlDataConnection));
webReport.Report.Dictionary.Connections.Add(mssqlDataConnection);
webReport.Report.Load(strRptPath);

DataSet dt = _comService.GetReportData();
((TableDataSource)((DataBand)((ReportPage)webReport.Report.Childobjects[0]).Bands[0]).DataSource).Table = dt.Tables[0];
webReport.Report.Prepare();
// save file in stream
Stream stream = new MemoryStream();
webReport.Report.Export(new PDFExport(),stream);
stream.Position = 0;
// return stream in browser
return File(stream,"application/x-msdownload","report.pdf");

如果我将.Prepare() 放在DataTable 的分配之前,我会得到原始数据;使用此示例中的代码在运行时出现错误“Text6: Error in expression: Table1.Code” 提供 DataTable 的 sql 与报表数据源中定义的查询完全相同。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)