Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve data from mdx query in c#?

Tags:

c#

mdx

adomd.net

I am trying to get data from an MDX query using the Adomdclient library. I relied on this example http://www.yaldex.com/sql_server/progsqlsvr-CHP-20-SECT-6.html.

MDX query:

SELECT {[Measures].[Cantidad Vta],[Measures].[Monto Vta],[Measures].[ExistenciaHistorica],[Measures].[Valor Inventario historico]} DIMENSION PROPERTIES PARENT_UNIQUE_NAME ON COLUMNS , NON EMPTY Hierarchize({DrilldownLevel({[DIM SUBMARCA].[Código].[All]})}) DIMENSION PROPERTIES PARENT_UNIQUE_NAME ON ROWS FROM (SELECT ({[DIM TIENDA].[JERARQUIA TIENDA].[Región].&[Bodega],[DIM TIENDA].[JERARQUIA TIENDA].[Región].&[Cadena],[DIM TIENDA].[JERARQUIA TIENDA].[Región].&[Outlet]}) ON COLUMNS FROM [JUGUETRONHQ]) WHERE ([DIM FECHA VENTA].[JERARQUIA FECHA VENTA].[Time].&[2012-01-01T00:00:00],[DIM FECHA EXISTENCIA].[JERARQUIA FECHA EXISTENCIA].[All]) CELL PROPERTIES VALUE

Like other namespaces such as SqlClient, use a connection, a command and a datareader:

using Microsoft.AnalysisServices.AdomdClient;

...

using (AdomdConnection con = new AdomdConnection(connection_string))
{
  con.Open();

  using (AdomdCommand command = new AdomdCommand(query, con)) 
  {
    using (AdomdDataReader reader = command.ExecuteReader()) 
    {
      while (reader.Read())
      {
        for (int i = 0; i < reader.FieldCount; i++)
          Console.Write(reader[i] + (i == reader.FieldCount - 1 ? "" : ", "));
          Console.WriteLine("");

      }
    }
  }
}

However, this snippet only shows 4 of 5 columns correctly:

[DIM SUBMARCA].[Código].[All], , , 3, 825

It must be:

115200081, , , 3, 825

Perhaps need a cast but I don't know how to do it.

like image 663
auraham Avatar asked Nov 14 '22 12:11

auraham


1 Answers

This looks like a problem with the MDX query, not the retrieval of the data. It's not correctly constraining on the [DIM SUBMARCA].[Código] dimension.

like image 155
Bas Avatar answered Nov 16 '22 02:11

Bas