1、引用DLL?
????? 按照之前安裝的MS SQLServer的步驟安裝完成后,發(fā)現(xiàn)在新建的項(xiàng)目中“Add Reference”時(shí)居然找不到Microsoft.AnalysisServices.AdomdClient命名空間,不知道是什么狀況?只好添加DLL了,在“C:\Program Files\Microsoft.NET\ADOMD.NET\100\Microsoft.AnalysisServices.AdomdClient.dll”下找到了該文件,該文件的最后修改時(shí)間是2009年3月30日,534KB。如圖:
圖 AdomdClient.dll的磁盤(pán)路徑
2、連接字符串?
本人覺(jué)得這一塊和ADO.NET沒(méi)有太大的區(qū)別,此處我使用的連接字符串是:Provider=SQLNCLI10.1;Data Source=localhost;Integrated Security=SSPI;Initial Catalog=BPDW; ,該字符串可以在數(shù)據(jù)源設(shè)計(jì)器中找到,所以根本無(wú)需記憶,會(huì)找即可。
圖 連接字符串
3、第一個(gè)程序
?

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 ] . [ 國(guó)家名稱(chēng) ] . & [ 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
}
?
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

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