title: How to retrieve data from mdx query in c#?
body: <p>I am trying to get data from an MDX query using the Adomdclient library. I relied on this example <a href="http://www.yaldex.com/sql_server/progsqlsvr-CHP-20-SECT-6.html" rel="noreferrer">http://www.yaldex.com/sql_server/progsqlsvr-CHP-20-SECT-6.html</a>.</p>
  
  <p>MDX query:</p>
  
  <pre><code>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].&amp;[Bodega],[DIM TIENDA].[JERARQUIA TIENDA].[Región].&amp;[Cadena],[DIM TIENDA].[JERARQUIA TIENDA].[Región].&amp;[Outlet]}) ON COLUMNS FROM [JUGUETRONHQ]) WHERE ([DIM FECHA VENTA].[JERARQUIA FECHA VENTA].[Time].&amp;[2012-01-01T00:00:00],[DIM FECHA EXISTENCIA].[JERARQUIA FECHA EXISTENCIA].[All]) CELL PROPERTIES VALUE
  </code></pre>
  
  <p>Like other namespaces such as SqlClient, use a connection, a command and a datareader:</p>
  
  <pre><code>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 &lt; reader.FieldCount; i++)
            Console.Write(reader[i] + (i == reader.FieldCount - 1 ? "" : ", "));
            Console.WriteLine("");
  
        }
      }
    }
  }
  </code></pre>
  
  <p>However, this snippet only shows 4 of 5 columns correctly:</p>
  
  <pre><code>[DIM SUBMARCA].[Código].[All], , , 3, 825
  </code></pre>
  
  <p>It must be:</p>
  
  <pre><code>115200081, , , 3, 825
  </code></pre>
  
  <p>Perhaps need a cast but I don't know how to do it.</p>