【问题标题】:Crystal Report with two DataSet (xsd) sources具有两个数据集 (xsd) 源的 Crystal Report
【发布时间】:2012-01-08 08:55:21
【问题描述】:

我有一份报告需要从我的应用程序 DAL 的两个逻辑区域 Vendors.xsd 和 Customers.xsd 中获取数据。我可以使用 Database Expert 将 DataSets 和它们的 DataTables 都放入报告中,但是我得到了这个错误:

此报告中使用了多个数据源或存储过程。 请确保没有添加 SQL 表达式并且没有服务器端 group_by 执行。

关于报表构建/设计的一切似乎都运行良好。当我实际运行报告时,它要求我登录到两个 DataSet 之一(似乎是我添加的第二个)并且没有获取数据。

我测试并确认如果我将所有表放在一个 xsd 中开始,我没有这个问题。

编辑

这是我用来加载报告的代码:

Protected Sub CrystalReportViewer1_Init(sender As Object, e As EventArgs) Handles CrystalReportViewer1.Init
    'Get Customer ID param
    Dim CustomerID As Integer
    If Not Integer.TryParse(Request.QueryString("CustomerID"), CustomerID) Then
        CancelReportOnError("You must provide a customer ID!")
    End If

    'Get address type ID param
    Dim AddressTypeID As Integer
    If Not Integer.TryParse(Request.QueryString("AddressTypeID"), AddressTypeID) Then
        CancelReportOnError("You must provide an address type!")
    End If

    'Gather report data --
    'Address
    Dim customersControl As New BLL.Customers()
    Dim AddressData As DAL.Customers.AddressesDataTable = customersControl.GetAddressByCustomerID(CustomerID, AddressTypeID)
    AddressData.TableName = "Addresses"

    'Customer
    Dim CustomerData As DAL.Customers.CustomersDataTable = customersControl.GetCustomerByID(CustomerID)
    CustomerData.TableName = "Customers"

    'Confirm customer exists
    If CustomerData.Count = 0 Or AddressData.Count = 0 Then
        CancelReportOnError(String.Format("Could not find Customer with ID {0}", CustomerID))
    End If

    'Vendor
    Dim vendorsControl As New BLL.Vendors()
    Dim VendorData As DAL.Vendors.VendorsDataTable = vendorsControl.GetVendordByCustomerID(CustomerID)
    VendorData.TableName = "Vendors"

    'Confirm vendor exists
    If VendorData.Count = 0 Then
        CancelReportOnError(String.Format("Could not find a Vendor associated with Customer ID {0}", CustomerID))
    End If

    'Build data source
    Dim ReportData As New DataSet()
    ReportData.Tables.Add(VendorData)
    ReportData.Tables.Add(CustomerData)
    ReportData.Tables.Add(AddressData)
    ReportData.Relations.Add(CustomerData.CustomerIDColumn, AddressData.CustomerIDColumn)
    ReportData.Relations.Add(VendorData.VendorIDColumn, CustomerData.VendorIDColumn)

    'Load the report
    Dim Report As New ReportDocument()
    Report.Load(Server.MapPath("~/Members/Customers/MailingEnvelope.rpt"))
    Report.SetDataSource(ReportData)

    'Set the report to our viewer
    CrystalReportViewer1.ReportSource = Report
    CrystalReportViewer1.DataBind()
End Sub

【问题讨论】:

    标签: asp.net visual-studio crystal-reports dataset


    【解决方案1】:

    除非您在逻辑上将这两个数据集联系在一起,否则 Crystal 将无法在同一个报表中使用它们。

    但是,如果您创建一个或两个子报表(取决于数据是否相关),并为每个子报表添加适当的数据集,Crystal 会更快乐。

    有关新信息的更新

    问题在于您有两组不同的数据关系:客户/地址和客户/供应商。本质上,Crystal 不知道如何将这些拉入 1 个大 SQL 语句,因为供应商和地址之间没有关系。

    解决方案是在主报表中仅包含客户信息,然后为供应商数据创建一个子报表,为地址数据创建一个子报表。这些子报表可以通过 customerid 链接,以便在您为多个客户运行此报表的情况下,Crystal 可以自动提取正确的客户信息。

    就目前而言,您应该能够只将供应商表分配给一个子报表的数据源,并将地址数据分配给另一个。

    【讨论】:

    • 如何在逻辑上将我的数据集联系在一起?我添加了将我的报告加载到原始帖子的代码 sn-p。
    • @just.another.programmer:根据您更新的问题使用附加信息更新了答案。
    猜你喜欢
    • 2012-03-23
    • 2010-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-06
    • 2013-10-23
    相关资源
    最近更新 更多