Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

.NET Reporting Tool Tutorial - 2

0.00/5 (No votes)
21 Apr 2013 1  
Second tutorial for loading data through code - Sqlite

Introduction

This is the second tutorial for ReportMax free reporting tool for .NET developers (http://www.cppmax.com). As a pre-requisite, you need to read Tutorial 1. This new tutorial shows the developer how to connect to virtually any data source (in this example Sqlite) by code and without using Ole DB Providers.

Background

If you have your own method of accessing a database, or if you do not have access to an Ole Db provider for that data source, or if you wish to access a custom data source (i.e. XML file), then you need to override SetDataSource event and write your own code to read from the database and bind it to the report. In this example, I will show how to connect to a Sqlite database using System.Data.Sqlite.dll and fill out the data set for the report to read from.

Using the Code

You will need ReportMax version 2.3. Please make sure this is the version you have even if you have downloaded it yesterday. It is under active development and gets updated frequently.

Report Designer

  1. Follow the steps to create the report in case you have not done so in Tutorial 1.
  2. Make sure the ConnectionString and SQL properties are blank.
  3. Make sure the ReportFile property is set to the correct MainReport.rpm path under the sample.

Report Viewer

  1. Add a reference to System.Data.Sqlite.dll from the sample folder. Since this is a version 2.0 DLL, you need to enable mixed assembly mode. Create or open the SqliteReportMaxSample.exe.config and paste the following code. Place this file where the executable is located:
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" />
    </startup>
    <runtime>
    <generatePublisherEvidence enabled="false" />
    </runtime>
    </configuration>
  2. Click on the ReportMaxViewer control on the Form designer. Click the Events in the Properties Window. Double click Report_SetDataSource Event. An event handler will be created and the focus will be moved to the code editor.
  3. Write the following statement at the top of the file:
    using System.Data.Sqlite;
  4. Paste the following code inside SetDataSource event handler:
    dataset = new DataSet();
    string connString = string.Format("Data Source={0};Version=3;", "..\\..\\Cities.db");
    SQLiteConnection con = new SQLiteConnection(connString);
    con.Open();
    string sql = "SELECT Code, CountryName, CityName, City.Population FROM Country, 
    City WHERE Country.Code = City.Country ORDER BY CountryName;";
    SQLiteDataAdapter da = new SQLiteDataAdapter(sql, con);
    da.Fill(dataset);
    con.Clone();
  5. Run the application. You should see the report.

Points of Interest

The sample project is provided with this tip.

History

  • Initial release

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here