locked
Reports in ASPNET 3.5 with a Service Layer RRS feed

  • Question

  • User961285720 posted
    Hi, I'm developing a solution with an architecture like this

    Presentation
    Service Layer
    Business Layer
    Data Layer
    Database

    They
    communicate each other with DTOs.

    My problem becomes when I want to create
    reports, I don't used .xsd nor .xss files, and I don't know if I should use Crystal
    Report or Report Viewer. When I go to tutorials I see all of them using .xsd
    and .xss and I don't want, or at least I don't see it worth enough to do it just
    for the reports...How can I create the report using the output of my Service
    Layer (IEnumerable's)? What's the best approach here Crystal Reports or Report
    Viewer?

    Thanks in advance! Daniel.
    Friday, December 25, 2009 12:01 PM

Answers

  • User78336405 posted

    Hi,

    You can add reports to your application using the version of Crystal Reports that comes with VS.NET. Right click your project in Solution Explorer and select Add | Add New Item | Crystal Reports.

    The DataSource for your report can be based on an XML Schema (XSD) file. Schemas files are XML files that describe the columns in your datatable. (To see how to set the DataSource to a .NET DLL click here). The easiest way to create a schema for your data is to call your dataset's WriteXmlSchema method:

    Imports System.Data.OleDb

    Dim strConnection As String = "..."
        Dim Connection As New OleDbConnection(strConnection)
        Dim DS As New DataSet
        
        Dim strSQL As String = "Select * From Customers"
        Dim DA As New OleDbDataAdapter(strSQL, Connection)
        DA.Fill(DS, "Customers")
        
        strSQL = "Select * From Orders"
        DA = New OleDbDataAdapter(strSQL, Connection)
        DA.Fill(DS, "Orders")
    
        DS.WriteXmlSchema("C:\SomeFolder\MySchema.xsd")


     

    To add the schema to your solution right click your project in Solution Explorer and select Add | Add Existing Item and navigate to your .XSD file.

    In your Crystal Report you reference the schema by opening the Field Explorer, right clicking Database Fields, selecting Database Expert, expanding the Create New Connection node, and the ADO.NET (XML) node then double clicking Make New Connection. At the ADO.NET (XML) dialog set the File Path to your XSD file by clicking the elipses and navigating to the schema file. Hit Finish when done.

    Your schema will appear under the ADO.NET (XML) node in the Available Data Sources pane. Select the desired datatable within it and add it to the Selected Tables pane. Hit OK when done.

    Now in the Field Explorer under the Database Fields node you will see your datatable and its fields which you can drag onto the report.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, December 27, 2009 9:40 PM