2012-04-02 6 views
2

IはC#でクエリを実行するために、次のコードを使用:問合せOLAPサーバ

AdomdConnection con = new AdomdConnection("Datasource=local;..."); 

      con.Open(); 
      AdomdCommand command = con.CreateCommand(); 
      command.CommandText = input; 

      AdomdDataReader reader = command.ExecuteReader(); 
    while (reader.Read()) 
      { 
for(i =0; i<reader.fieldCount; i++){ 
     a[i]=reader.GetString(i); 
} 
return a; 

Howeever、このコードは、各セルの階層に完全なパスを返します。つまり、データの各行は[AllGeography、Canada、Vancouver、Allproduct、bikes、accessories、297483]と同じです。 私は葉とメジャー値だけを取得したい:[vancouver、accessories、297483]。私は何をすべきか?どのように私は葉を指定することができますか?

答えて

2

MDXクエリの結果は実際には多目的であるため、私は自分自身がExecuteCellSetをより快適に感じるようになりました。 CellSet全体を取得し、座標を使ってMeasuresを取得します。あなたはそれがクエリで第三DIMENTIONとセルセットで第三cooridinateだろうよりも、いくつかの対策を、持っている場合

AdomdCommand cmd = conn.CreateCommand(); 
cmd.CommandText = @"SELECT 
      [Geography].[Geography].[Country].&[Canada].Children ON 0, 
      [Product].[Id] ON 1 
      FROM [Cube] 
      WHERE [Measures].[Your Measure]"; 

CellSet cs = cmd.ExecuteCellSet(); 

TupleCollection CanadaChildren = cs.Axes[0].Set.Tuples; 
TupleCollection ProductIds = cs.Axes[1].Set.Tuples; 

for (int row = 0; row < CanadaChildren.Count; row++) 
{ 
    for (int col = 0; col < ProductIds.Count; col++) 
    { 
     a[i++] = cs.Cells[col, row].Value; 
    } 
} 
conn.Close(); 

:(クエリ内の1つの指標を持っている場合)例えば