Knowledgebase
How to Fill The Cube With Data
Posted by Ilya Terehin on 26 January 2015 10:25 AM

How to Fill The Cube With Data

Filling methods Quick Reference Note
Using the filling methods of TableAdaptor Connecting directly to designtime. No need to write a single line of code Loads data into memory two times.
Create properties in partial classes. Need to write additional code to the partial classes and also write the connection string and the query string. Allows you to load only the data you need.
OnInitDataSet event handler You must subscribe to the events of the cube and write a method of creating IDataReader or IDbCommand Allows you to load only the data you need. You can control the way it works in run-time.

 

Using the built-in filling methods of TableAdaptor

With such a connection you do not need to write a single line of code. Here is what you can do to connect:

  1. Create a dataset.
  2. Assign it to TOLAPCube.DataSet. To make the newly created dataset appear in the list the project must be rebuilt.

 

WFGettingStartedSelectDataSet2

 

You can also connect in runtime:

var northwind = new RadarSoft.WinForms.DemoDesktop.Northwind();

var olapcube = new TOLAPCube();

olapcube.DataSet = northwind;

 

Note

This method does not require you to write code. However the data will be loaded twice - from the database to the DataSet and from DataSet to the internal cube structure.Use this approach for small (about a thousand entries) datasets and/or limited memory resources.

 

Create properties in partial classes

  1. Create a dataset;
  2. Assign it to TOLAPCube.DataSet. To make the newly created dataset appear in the list the project must be rebuilt;
  3. Create a partial class for your TableAdaptorNNN dataset. Classes must implement a property public System.Data.IDataReader DataReader { get {...} }

On dataset initialization TOLAPCube will use these properties to read data from a data source. The data will be read right to TOLAPCube.
Here is an example of a partial class:

public partial class CategoriesTableAdapter : System.ComponentModel.Component

{

    public System.Data.IDataReader DataReader

    {

        get

        {

            string queryString = "SELECT CategoryID, CategoryName, Description FROM Categories";

            OleDbCommand command = new OleDbCommand(queryString, new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=d:\\Data\\OLAPDemo.mdb"));

            command.Connection.Open();

            return command.ExecuteReader();

        }

    }

}

 

Note

Use this approach if:

  • You have a large database (more than a hundred thousand records).
  • You need to save memory (the data from the database will be read right into TOLAPCube).
  • You have access to the TableAdaptors code.
  • There's no need to change the connection string and/or the reading data.

 

OnInitDataSet event handler

1. Create a dataset.

2. Assign it to TOLAPCube.DataSet. To make the newly created dataset appear in the list the project must be rebuilt.

3. To create IDataReader and IDbCommand use TOLAPCube.OnInitDataSet event handler:

olapcube.OnInitDataSet += DataSetDataReader_OnInitDataSet;

void DataSetDataReader_OnInitDataSet(object sender, InitDataSetHandlerArgs e)

{

    if (e.ConnectionString == null) 

        return null;

    e.CreateDataReader = () => {

        var command = new OleDbCommand(e.QueryString, new OleDbConnection(e.ConnectionString));

        command.Connection.Open();

        return command.ExecuteReader();

    };

}


The properties of InitDataSetHandlerArgs class:

Type Name Desription
string ConnectionString Connection string. The value will be filled if the TableAdaptor has the property Connection filled. This is how VS does by default.
string QueryString The query string. Contains the SELECT query to get all table fields. You can make the query select only the fields that are really needed in the cube to make it work faster.
string DataTableName Name of the table
IEnumerable<string> DataColumns The names of table columns
Func<IDataReader> CreateDataReader Function to create an instance of a class that implements IDataReader. If the property is not empty, then the result of the call will be used to fill the table cube
Func<IDbCommand> CreateDbCommand Function to create an instance of a class that implements the IDbCommand. If the property is not empty, then the result of the call will be used to fill the table cube

 

Note

Use this approach if:

  • You have a large database (more than a hundred thousand records).
  • You need to save memory (the data from the database will be read right into TOLAPCube).
  • There's no need to change the connection string and/or the reading data.

 

Note

TOLAPCube uses the following algorithm to choose the way to read the data from the dataset.

  1. The event handler OnInitDataSet is called on. If CreateDataReader or CreateDbCommand methods are returned then they are used to to read data.
  2. If no method returned then TOLAPCube looks for the open methods in table adapters.
    public System.Data.IDataReader DataReader { get {...}}
    or
    public System.Data.IDbCommand DataReader { get {...}}
    in the partial classes.
    If found then they are used to read data from the dataset. 
  3. Otherwise the TableAdaptor.Fill method is called on and then TOLAPCube reads the data from the dataset.


Attachments 
 
(1 vote(s))
This article was helpful
This article was not helpful

Help Desk Software by Kayako Resolve