Click here to Skip to main content
15,881,882 members
Articles / Programming Languages / XML
Tip/Trick

.NET Reporting Tool Tutorial - 2

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
21 Apr 2013CPOL2 min read 30.2K   1K   8   9
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
    <?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:
    C#
    using System.Data.Sqlite;
  4. Paste the following code inside SetDataSource event handler:
    C#
    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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) CppMax
Canada Canada
Check out our light-weight, easy to use and powerful Microsoft .net reporting tool www.cppmax.ca

Comments and Discussions

 
QuestionAdding a second page Pin
Member 1073668923-Mar-15 7:31
Member 1073668923-Mar-15 7:31 
Questionassign parameter value to a field in the report Pin
Member 107366895-Mar-15 11:24
Member 107366895-Mar-15 11:24 
QuestionSetDataSource not binding to the rpm file Pin
Member 107366895-Mar-15 4:43
Member 107366895-Mar-15 4:43 
AnswerRe: SetDataSource not binding to the rpm file Pin
emadns5-Mar-15 4:49
emadns5-Mar-15 4:49 
GeneralRe: SetDataSource not binding to the rpm file Pin
Member 107366895-Mar-15 5:00
Member 107366895-Mar-15 5:00 
GeneralRe: SetDataSource not binding to the rpm file Pin
Member 107366895-Mar-15 5:07
Member 107366895-Mar-15 5:07 
GeneralRe: SetDataSource not binding to the rpm file Pin
emadns5-Mar-15 5:19
emadns5-Mar-15 5:19 
GeneralRe: SetDataSource not binding to the rpm file Pin
Member 107366895-Mar-15 6:23
Member 107366895-Mar-15 6:23 
GeneralRe: SetDataSource not binding to the rpm file Pin
Member 107366895-Mar-15 6:51
Member 107366895-Mar-15 6:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.