ReportViewer 从数据表中生成报告

发布于 2024-09-08 14:43:17 字数 257 浏览 2 评论 0原文

我想知道是否有一种方法可以通过 SQL 查询为 ReportViewer 设计报表。那么,我可以从 SQL 查询中获取制作报告所需的所有数据,然后在设计器中设计报告吗?

我对 ReportViewer 很陌生,而且很困惑。现在我可以看到我可以通过向导填充数据集,但是据我所知,没有办法在其中抛出 SQL 查询,然后从中进行设计。

我想要的是否可能,或者我必须使用 DataGridView 吗?由于打印/导出支持,我​​真的很想使用报表查看器。有关于这个主题的文献吗?

I was wondering if there was a way to design a report for ReportViewer from a SQL query. So from the SQL query I'd get all the data I need to make a report and then design the report in the designer?

I am very new to ReportViewer and I am quite confused. Right now I can see I can populate the DataSet from a wizard, however as far as I can see there is no way to throw a SQL query in there and then design from that.

Is what I want even possible or will I have to use a DataGridView? I really want to use the reportviewer because of the printing/exporting support. Is there any literature available on the subject?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

百合的盛世恋 2024-09-15 14:43:17

如果您使用的是 LocalReport 类 ( reportViewer.LocalReport)而不是 SSRS(那里的所有内容都是可点击的),示例位于链接中。

ReportDataSource 类 具有接受 DataTable 对象。

您只需设计报表并将数据集添加到 RDL 文件中。

编辑:将数据集插入为 xml,如下所示:

<DataSources>
    <DataSource Name="MyDataSource">
      <ConnectionProperties>
        <ConnectString />
        <DataProvider>SQL</DataProvider>
      </ConnectionProperties>
    </DataSource>
    ...
</DataSources>

<DataSets>
    <DataSet Name="MyDataSet">
      <Query>
        <CommandText>MyDataSet</CommandText>
        <DataSourceName>MyDataSource</DataSourceName>
      </Query>
      <Fields>
        <Field Name="Id">
          <DataField>ID</DataField>
        </Field>
        <Field Name="SomeOtherField">
          <DataField>SOME_OTHER_FIELD</DataField>
        </Field>
      </Fields>
   </DataSet>
</DataSets>

If you are using the LocalReport Class (reportViewer.LocalReport) and not the SSRS (everything is clickable there), a sample is in the link.

ReportDataSource Class has constructor that accepts a DataTable object.

You only need to design the report and add datasets to the RDL file.

Edit: Insert datasets as xml like this:

<DataSources>
    <DataSource Name="MyDataSource">
      <ConnectionProperties>
        <ConnectString />
        <DataProvider>SQL</DataProvider>
      </ConnectionProperties>
    </DataSource>
    ...
</DataSources>

<DataSets>
    <DataSet Name="MyDataSet">
      <Query>
        <CommandText>MyDataSet</CommandText>
        <DataSourceName>MyDataSource</DataSourceName>
      </Query>
      <Fields>
        <Field Name="Id">
          <DataField>ID</DataField>
        </Field>
        <Field Name="SomeOtherField">
          <DataField>SOME_OTHER_FIELD</DataField>
        </Field>
      </Fields>
   </DataSet>
</DataSets>
我要还你自由 2024-09-15 14:43:17

首先,这取决于您使用的是本地报表还是服务器报表(SQL Server Reporting Services)。两者都可以显示在 ReportViewer 控件中。

对于服务器报告来说,事情很简单。该报告包含数据源,您可以选择使用 SQL 语句或现有存储过程。

对于本地报道来说,事情有点困难。您必须设计一个包含您的数据的类型化数据集。这可以像往常一样从任何内容(SQL 命令、存储过程等)中填充。然后,您可以将此数据集的实例分配给报表的数据源。

请注意,虽然服务器报告允许您过滤数据,但在使用本地报告时您必须自己编写一些过滤功能。

Firstly, it depends on whether you're using a local report or a server report (SQL Server Reporting Services). Both can be displayed within the ReportViewer control.

For a server report, things are simple. The report contains data sources and you can either choose to use an SQL statement or an existing stored procedure.

For a local report, things are a bit more difficult. You'd have to design a typed data set that contains your data. This can be filled from anything as usual (SQL command, stored procedure, etc.). You'd then assign the instance of this data set to the report's data source.

Please note that while the server reports allow you to filter the data, you'd have to write some filtering feature yourself when using local reports.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文