Home > English > Simple Tabular Report Generation in WPF

Simple Tabular Report Generation in WPF

This post is on using the power of the ReportViewer in WPF to build simple tabular reports on the fly. I did a presentation on this a while back and I noticed that there is some interest in building reports and having the ability to query your database on the fly without the need for SQL Server Management Studio or MS Access.

The sample included in this post is a simple mock up that can grow with time. It gives you the ability to connect to any SQL Server backend. You can then write your SQL in the editor. Finally, you can preview your data, make any changes you want to ensure that it is ready for a generating a report. You then click on the Generate Report button and the Preview Report tab becomes selected rendering a dynamic report based on your query. With very little code, you get a simple query editor, code generator, and local report viewer.

In this first post we will just take a look at the user interface but in a following post, we will cover the code necessary to get this working.

My example is using the AdventureWorks database but you can use whatever database you like. When the application first starts, are presented with the following window:

Click on the button as indicated in the following screen shot:

Setting up the Connection

Follow the dialog and enter in your information for creating a connection.

Dialog for creating a database connection.

You can test your connection and verify that it is correct.

Dialog for testing the connection.

Click the Connect button to create the connection. Type in the query you wish to perform:

Write in your SQL query.

You can now either execute the query or parse it. The following is a screen shot of the query executed:

Query and metadata results displayed.

As you can see, we get our results but we also get a grid in the middle that provides us with a bit of metadata for formatting our report. You can also provide a title for the report.

Metadata set for report generation.

Then by clicking the Generate Report button, we see the following:

Report rendered in the ReportViewer control.

By now you can see that it is very easy to create some dynamic reports in very little time. In the next post we will go over the code and architecture required to get this to work. I have included the slides, source code, and a walk-through from my presentation.

Hope this helps….

Advertisements
  1. May 29, 2011 at 1:14 pm

    Thanks for posting

  2. mardymonkeykier
    August 10, 2011 at 1:34 pm

    Hi Matt,

    I was looking through the code and was just wondering if this relies on MS SQL or if I could use it with MySQL and the .NET connector?

    • August 10, 2011 at 4:28 pm

      I believe that the code currently uses a SQL data provider but you can modify the XML for the report definition to support OLEDB or some other provider.

      Hope that helps,

      Matt

  1. May 12, 2011 at 1:26 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: