Make Reports Quickly With ASP.NET and XML
page 1 of 1
Published: 07 Jul 2004
Unedited - Community Contributed
Abstract
Sometimes you need to create reports quickly. You might not always have time to format fancy reports containing graphs. Or maybe you have to create reports that do not need graphs. Reusing one ASP.NET web page you can display many reports.
by Andrew Mooney
Feedback
Average Rating: 
Views (Total / Last 10 Days): 10686/ 11

[Download Code] | [Run Sample]
Sometimes you need to create reports quickly. You might not always have time to format fancy reports containing graphs. Or maybe you need to create a report that doesn't need graphs. By reusing one ASP.NET web page you can quickly make reports that are stored in XML files. The sample that is included in the download demonstrates how you can display up to three different database queries, using three DataGrids, on the same page. Each report is an XML file that contains a title for the web page and a subtitle, connection string, SQL select statement, and page size for each database query.

Example XML report file:

<?xml version="1.0" encoding="utf-8" ?>
<XmlReport>
  <Page>
    <Title>Products</Title>
  </Page>
  <Report>
    <Title>Product List</Title>
    <ConnectionProvider=Microsoft>.Jet.OLEDB.4.0; Data Source=\products.mdb;</Connection>
    <Sql>Select ProductID, ProductName, UnitPrice From Products;</Sql>
    <PageSize>10</PageSize>
  </Report>
  <Report>
    <Title>Product Summary</Title>
    <ConnectionProvider=Microsoft>.Jet.OLEDB.4.0; Data Source=\products.mdb;</Connection>
    <Sql>Select Count(ProductID) As [Product Count] From Products;</Sql>
    <PageSize></PageSize>
  </Report>
</XmlReport>

The name of the report (XML file) is sent in the QueryString without the file extension (.xml). For example: reports.aspx?report=reportname. The XML report is loaded and the "Reports" table is iterated to bind data to the DataGrids. This would be a perfect place to use a control array, but ASP.NET does not support control arrays. The sample shows a way around this handicap.

OleDb is used to connect to the data sources so you can use any OleDb database. Another neat feature is that each report has its own connection string. This allows you to display reports from different databases on the same page. Each report has a setting for page size; if left blank paging will not be enabled for that report.

The download is a complete working solution that I am currently using in-house. The download contains an Access database and a test report (Test.xml) that displays a product list and a summary. Now, when you want to create a report, just create an XML report file and save it in the reports directory. Then create a link to the reports.aspx page with your new file name (minus the extension) and your report is made. If you create many reports that don't require graphs you will save much time reusing this code sample.



User Comments

No comments posted yet.






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-03-29 9:34:11 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search