一、打开Visiual Studio 2010,新建网站,并且添加Default.aspx页面。
二、添加引用Microsoft.AnalysisServices.AdomdClient.dll(注意:有可能有些vs版本没有这个dll,可以到C:\Program Files (x86)\Microsoft.NET\ADOMD.NET\100目录下拷贝一份)
三、Default.aspx.cs上加上如下代码:
在Page_Load加上如下代码:
string connectionString = "Provider=SQLNCLI10.1;Data Source=localhost;Integrated Security=SSPI;Initial Catalog=NewHG";
try
{
AdomdConnection connection;
connection = new AdomdConnection(connectionString);
connection.Open();
//获取立方体的集合
CubeCollection mycubes = connection.Cubes;
Label2.Text = "本连接共有立方体数目为:" + mycubes.Count.ToString() + "个,它们分别为: \r\n \r\n";
AdomdCommand command;
string mdx = "select [城市].[City N].[City N] on COLUMNS,[单位2].[UNTN].[UNTN] on ROWS from [New HG]";
command = new AdomdCommand(mdx, connection);
CellSet cellSet = command.ExecuteCellSet();
System.Text.StringBuilder result = new System.Text.StringBuilder();
result.Append("\t");
TupleCollection tuplesOnColumns = cellSet.Axes[0].Set.Tuples;
foreach (Microsoft.AnalysisServices.AdomdClient.Tuple column in tuplesOnColumns)
{
result.Append(column.Members[0].Caption + "\t");
}
result.AppendLine();
TupleCollection tuplesOnRows = cellSet.Axes[1].Set.Tuples;
for (int row = 0; row < tuplesOnRows.Count; row++)
{
result.Append(tuplesOnRows[row].Members[0].Caption + "\t");
for (int col = 0; col < tuplesOnColumns.Count; col++)
{
result.Append(cellSet.Cells[col, row].FormattedValue + "\t");
}
result.AppendLine();
}
connection.Close();
String str = result.ToString();
Label1.Text = "连接成功";
}
catch (Exception ex)
{
Label1.Text = ex.Message;
return;
}
跑一下,结果就出来了:
另外一个解析网站:http://www.cnblogs.com/aspnetx/archive/2010/11/12/1875469.html