gpt4 book ai didi

c# - 查询 OLAP 服务器

转载 作者:太空宇宙 更新时间:2023-11-03 11:24:19 24 4
gpt4 key购买 nike

我使用以下代码在 C# 中执行查询:

 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;

但是,此代码返回每个单元格在层次结构中的完整路径。即,每一行数据就像 [AllGeography, Canada, Vancouver, Allproduct, bikes, accessories, 297483]。我只想检索叶子和度量值:[vancouver, accessories, 297483]。我应该怎么办?如何指定叶子?

最佳答案

因为MDX查询的结果其实是多维的,我觉得自己用ExecuteCellSet更舒服。您可以获得整个 CellSet,然后通过坐标获得 Measures。

例如(如果您在查询中有一个度量):

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();

如果您有多个度量,那么它将是查询中的第三维和单元集中的第三坐标。

关于c# - 查询 OLAP 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9984624/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com