金辰在线金辰在线 ^_^, 崇尚技术,积累点滴,冰冻三尺!

导航

SSAS系列——【08】多维数据(程序展现Cube)

1、引用DLL?

      按照之前安装的MS SQLServer的步骤安装完成后,发现在新建的项目中“Add Reference”时居然找不到Microsoft.AnalysisServices.AdomdClient命名空间,不知道是什么状况?只好添加DLL了,在“C:\Program Files\Microsoft.NET\ADOMD.NET\100\Microsoft.AnalysisServices.AdomdClient.dll”下找到了该文件,该文件的最后修改时间是2009年3月30日,534KB。如图:

dll

图 AdomdClient.dll的磁盘路径

2、连接字符串?

本人觉得这一块和ADO.NET没有太大的区别,此处我使用的连接字符串是:Provider=SQLNCLI10.1;Data Source=localhost;Integrated Security=SSPI;Initial Catalog=BPDW; ,该字符串可以在数据源设计器中找到,所以根本无需记忆,会找即可。

ll

图 连接字符串

3、第一个程序

 

代码
string ReturnCommandUsingCellSet()
{
//Create a new string builder to store the results
System.
Text.StringBuilder result = new System.Text.StringBuilder();
//Connect to the local server
using (AdomdConnection conn
= new AdomdConnection("Provider=SQLNCLI10.1;Data Source=localhost;Integrated Security=SSPI;Initial Catalog=BPDW;"))
{
conn.
Open();
//Create a command, using this connection
AdomdCommand cmd
= conn.CreateCommand();
cmd.CommandText
= @"select {[Measures].[Oil Proved Reserves]} on columns ,{[Dim Time].[年份].&[19]} on rows from [BPDW]where [Dim Geography].[国家名称].&[Total Asia Pacific]&[China]";
//Execute the query, returning a cellset
CellSet cs
= cmd.ExecuteCellSet();
//Output the column captions from the first axis
//Note that this procedure assumes a single member exists per column.
result.Append("\t");
TupleCollection tuplesOnColumns
= cs.Axes[0].Set.Tuples;
foreach (Microsoft.AnalysisServices.AdomdClient.Tuple
column in tuplesOnColumns)
{
result.Append(
column.Members[0].Caption + "\t");
}
result.AppendLine();
//Output the row captions from the second axis and cell data
//Note that this procedure assumes a two-dimensional cellset
TupleCollection tuplesOnRows
= cs.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(cs.Cells
[col, row].FormattedValue + "\t");
}
result.AppendLine();
}
conn.
Close();
return result.ToString();
}
// using connection
}

 

posted on 2010-07-13 14:00  蔡辰  阅读(1838)  评论(0编辑  收藏  举报

      欢迎访问,    Email:caichen.2008@gmail.com;    QQ:23736722