【发布时间】:2021-03-06 11:48:28
【问题描述】:
我的任务是制作一个网页(aspx),它会自动读取rdlcs,并生成一个网页,顶部的参数为webelements,报告为页面的主要部分。
到目前为止,我已经尝试将文件作为 XML-Doc 读取,并从那里解析信息。但这可能会更简单。 (我对报告或rdl(c) 文件没有经验)。
我看到有一个DataSets/DataSet/Query/CommandText-Tag,它可以保存一个SQL-Statement。现在让我的老板和我自己假设,有可能让它自己已经提供这些信息,我对此进行了编码。另一方面,我看不到任何例子。
我当前的代码如下所示:
private string rdlcFilepath = "some/path/to/file.rdlc";
protected void Page_Load(object sender, EventArgs e) {
string sql = GetSqlStatementFromRdlcFile(rdlcFilepath);
DataTable dtTest = DatabseFacade.Execute_SQL(sql);
MainReportViewer.LocalReport.ReportPath = Server.MapPath(rdlcFilepath);
MainReportViewer.ProcessingMode = ProcessingMode.Local;
MainReportViewer.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", dtTest));
MainReportViewer.LocalReport.Refresh();
}
所以,我有两个理论:
-
CommandText-Tag 标记是“报告服务器”的标记,只能在ProcessingMode.Remote中使用,在本地模式下不相关。 - 我在处理整个事情时都错了。
如果 2 为真,那么问题可能是手动添加 dtTest,它应该有一些其他指令来使报告元素自己“拉”数据。
我的问题:
- 我的假设是否正确,或者发生了什么?
- 任何其他可能有帮助的提示/链接?
我可能会注意到,我在互联网上看到的每个教程/示例都使用了ProcessingMode.Local,使用了“外部”数据表和LocalReport.DataSources.Add 方式。
为了清楚起见,我们(我的老板和我的)理想的解决方案是一些“魔术”命令,它使 ReportViewer 使用 rdlc 文件中的信息连接到数据库,并显示结果。毕竟它包含所有信息,从连接字符串到 SQL 语句。
【问题讨论】:
标签: c# reportviewer