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。如圖:
圖 AdomdClient.dll的磁盤路徑
2、連接字符串?
本人覺得這一塊和ADO.NET沒有太大的區別,此處我使用的連接字符串是:Provider=SQLNCLI10.1;Data Source=localhost;Integrated Security=SSPI;Initial Catalog=BPDW; ,該字符串可以在數據源設計器中找到,所以根本無需記憶,會找即可。
圖 連接字符串
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
}
?
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
