just.another.programmer
just.another.programmer

Reputation: 8815

Crystal Report with two DataSet (xsd) sources

I have a report that needs to get data from two logical areas of my application's DAL, Vendors.xsd and Customers.xsd. I can use the Database Expert to put both DataSets and their DataTables in to the report, but I get this error:

More than one datasource or stored procedure has been used in this report. Please make sure that no SQL Expression is added and no server side group_by is performed.

Everything about the report building / design seems to work fine. When I actually run the report, it asks me to log on to one of the two DataSets (seems to be whichever one I add second) and does not get the data.

I tested and confirmed that I do not have this problem if I put all the tables in one xsd to begin with.

EDIT

Here's the code I'm using to load the report up:

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

Upvotes: 0

Views: 4749

Answers (1)

competent_tech
competent_tech

Reputation: 44971

Unless you tie the two datasets together logically, Crystal won't be able to use them in the same report.

However, if you create one or two subreports (depending on whether the data is related or not), and add the appropriate dataset to each subreport, Crystal will be much happier.

Update for new information in question

The problem is that you have two distinct sets of data relations: customer/address and customer/vendor. Essentially, Crystal doesn't know how to pull these into 1 big SQL statement because there is no relationship between vendor and address.

The solution is to have only the customer information in the main report, then have one subreport for the Vendor data and one subreport for the Address data. These subreports can be linked by the customerid so that in the event that you run this report for multiple customers, Crystal could automatically pull out the correct customer information.

As it stands now, you should be able to just assign the vendor table to one subreport's datasource and the addressdata to the other's.

Upvotes: 3

Related Questions