使用自定义对象作为 Microsoft Reports (.rdlc) 的源

发布于 2024-07-05 20:17:39 字数 123 浏览 7 评论 0原文

在某些情况下,我更喜欢使用自定义对象而不是强类型数据集和数据行。 然而,Microsoft Reporting(包含在 VS2005 中)似乎需要强类型数据集。

有没有办法使用我的自定义对象来设计和填充报告?

In some instances, I prefer working with custom objects instead of strongly typed datasets and data rows. However, it seems like Microsoft Reporting (included with VS2005) requires strongly typed datasets.

Is there a way to use my custom objects to design and populate reports?

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

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

发布评论

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

评论(3

靑春怀旧 2024-07-12 20:17:40

我永远无法从我的项目中的报告数据设置中选择我自己的 POCO 之一作为报告的模型 - 演练 不存在。 因此,我最终不得不编辑 XML 来定义类型和模仿数据源(它实际上并不存在于我的项目中)。

我将 Aies.Core.Model.Invoice.MemberInvoice 类型的数据分配给代码中的报表

reportViewer.LocalReport.DataSources.Add(new ReportDataSource("MemberInvoice", new[] { invoice1 }));

,自定义定义是:

  <DataSources>
    <DataSource Name="MemberInvoice">
      <ConnectionProperties>
        <DataProvider>System.Data.DataSet</DataProvider>
        <ConnectString>/* Local Connection */</ConnectString>
      </ConnectionProperties>
      <rd:DataSourceID>3fe04def-105a-4e9b-99db-630c1f8bb2c9</rd:DataSourceID>
    </DataSource>
  </DataSources>
  <DataSets>
    <DataSet Name="MemberInvoice">
      <Fields>
        <Field Name="MemberId">
          <DataField>MemberId</DataField>
          <rd:TypeName>System.Int32</rd:TypeName>
        </Field>
        <Field Name="DateOfIssue">
          <DataField>DateOfIssue</DataField>
          <rd:TypeName>System.DateTime</rd:TypeName>
        </Field>
        <Field Name="DateDue">
          <DataField>DateDue</DataField>
          <rd:TypeName>System.DateTime</rd:TypeName>
        </Field>
        <Field Name="Amount">
          <DataField>Amount</DataField>
          <rd:TypeName>System.Decimal</rd:TypeName>
        </Field>
      </Fields>
      <Query>
        <DataSourceName>MemberInvoice</DataSourceName>
        <CommandText>/* Local Query */</CommandText>
      </Query>
      <rd:DataSetInfo>
        <rd:DataSetName>Aies.Core.Model.Invoice</rd:DataSetName>
        <rd:TableName>MemberInvoiceData</rd:TableName>
        <rd:ObjectDataSourceSelectMethod>GetInvoices</rd:ObjectDataSourceSelectMethod>
        <rd:ObjectDataSourceSelectMethodSignature>System.Collections.Generic.IEnumerable`1[Aies.Core.Model.Invoice.MemberInvoice] GetInvoices()</rd:ObjectDataSourceSelectMethodSignature>
        <rd:ObjectDataSourceType>Aies.Core.Model.Invoice.MemberInvoiceData, Aies.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</rd:ObjectDataSourceType>
      </rd:DataSetInfo>
    </DataSet>
  </DataSets>

I could never choose one of my own POCOs in Report Data setup from my project to be a model for the report - the alleged 'global' option mentioned in the walkthrough was not there. So I ended up having to edit the XML to define the type and an imitation data source (which does not actually exist in my project).

I assign the data of type Aies.Core.Model.Invoice.MemberInvoice to the report in code

reportViewer.LocalReport.DataSources.Add(new ReportDataSource("MemberInvoice", new[] { invoice1 }));

And the custom definition is:

  <DataSources>
    <DataSource Name="MemberInvoice">
      <ConnectionProperties>
        <DataProvider>System.Data.DataSet</DataProvider>
        <ConnectString>/* Local Connection */</ConnectString>
      </ConnectionProperties>
      <rd:DataSourceID>3fe04def-105a-4e9b-99db-630c1f8bb2c9</rd:DataSourceID>
    </DataSource>
  </DataSources>
  <DataSets>
    <DataSet Name="MemberInvoice">
      <Fields>
        <Field Name="MemberId">
          <DataField>MemberId</DataField>
          <rd:TypeName>System.Int32</rd:TypeName>
        </Field>
        <Field Name="DateOfIssue">
          <DataField>DateOfIssue</DataField>
          <rd:TypeName>System.DateTime</rd:TypeName>
        </Field>
        <Field Name="DateDue">
          <DataField>DateDue</DataField>
          <rd:TypeName>System.DateTime</rd:TypeName>
        </Field>
        <Field Name="Amount">
          <DataField>Amount</DataField>
          <rd:TypeName>System.Decimal</rd:TypeName>
        </Field>
      </Fields>
      <Query>
        <DataSourceName>MemberInvoice</DataSourceName>
        <CommandText>/* Local Query */</CommandText>
      </Query>
      <rd:DataSetInfo>
        <rd:DataSetName>Aies.Core.Model.Invoice</rd:DataSetName>
        <rd:TableName>MemberInvoiceData</rd:TableName>
        <rd:ObjectDataSourceSelectMethod>GetInvoices</rd:ObjectDataSourceSelectMethod>
        <rd:ObjectDataSourceSelectMethodSignature>System.Collections.Generic.IEnumerable`1[Aies.Core.Model.Invoice.MemberInvoice] GetInvoices()</rd:ObjectDataSourceSelectMethodSignature>
        <rd:ObjectDataSourceType>Aies.Core.Model.Invoice.MemberInvoiceData, Aies.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</rd:ObjectDataSourceType>
      </rd:DataSetInfo>
    </DataSet>
  </DataSets>
允世 2024-07-12 20:17:40

我相信您可以设置 SSRS 来从或多或少任意的对象读取数据值。 此链接介绍API 中的 IDataReaderFieldProperties 对象 (IIRC) 允许您指定要调用以获取值的 getter 方法。

I believe you can set up SSRS to read data values from a more or less arbitrary object. This Link describes the IDataReaderFieldProperties object in the API which (IIRC) allows you to specify the getter method to invoke to get a value.

弥繁 2024-07-12 20:17:39

我找到了答案。 是的,这是可能的。 您只需在 Visual Studio 中添加自定义对象作为数据源即可。

http://www.gotreportviewer.com/objectdatasources/index.html

I found the answer. Yes, it's possible. You just have to add a custom object as a datasource in visual studio.

http://www.gotreportviewer.com/objectdatasources/index.html

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