原創(chuàng)|使用教程|編輯:王香|2018-07-17 13:51:12.000|閱讀 448 次
概述:本文詳細(xì)介紹如何將多維數(shù)據(jù)集連接到數(shù)據(jù)庫(kù)。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
通常,OLAP多維數(shù)據(jù)集中的數(shù)據(jù)是從數(shù)據(jù)庫(kù)加載的。要使用數(shù)據(jù)填充多維數(shù)據(jù)集,需要?jiǎng)?chuàng)建數(shù)據(jù)源,多維數(shù)據(jù)集可以接收以下數(shù)據(jù):
對(duì)于手動(dòng)填充或從數(shù)據(jù)庫(kù)填充的多維數(shù)據(jù)集,還需要?jiǎng)?chuàng)建或加載其表示,例如:可以從mds文件加載現(xiàn)成的表示,在本文中將介紹將多維數(shù)據(jù)集連接到數(shù)據(jù)庫(kù)的方法。
帶有數(shù)據(jù)方案的文件
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <slice version="2" timestamp="12.05.2017 16:31:09"> <fields> <field name="OrderNo" caption="OrderNo" Width="0" Height="0" PopupWidth="120" PopupShowAvailable="False" Collapsed="False" CollapsedSubGroup="False"/> <field name="PartNo" caption="PartNo" Width="0" Height="0" PopupWidth="120" PopupShowAvailable="False" Collapsed="False" CollapsedSubGroup="False"/> <field name="Qty" caption="Qty" Width="0" Height="0" PopupWidth="120" PopupShowAvailable="False" Collapsed="False" CollapsedSubGroup="False"/> <field name="CustNo" caption="CustNo" Width="0" Height="0" PopupWidth="120" PopupShowAvailable="False" Collapsed="False" CollapsedSubGroup="False"/> <field name="EmpNo" caption="EmpNo" Width="0" Height="0" PopupWidth="120" PopupShowAvailable="False" Collapsed="False" CollapsedSubGroup="False"/> <field name="SaleDate" caption="SaleDate" Width="0" Height="0" PopupWidth="120" PopupShowAvailable="False" Collapsed="False" CollapsedSubGroup="False"/> </fields> <page_fields alignment="taLeftJustify"> <fields/> </page_fields> <xaxis_fields alignment="taLeftJustify" GrandTotalPosition="fctp_Before" UseGrandTotalPositionFromMeasure="False" DefaultTypeSort="md_tsa_ByAxisValue" AxisType="at_Standard"> <fields/> <AdditionalGrandTotals/> </xaxis_fields> <yaxis_fields alignment="taLeftJustify" GrandTotalPosition="fctp_Before" UseGrandTotalPositionFromMeasure="False" DefaultTypeSort="md_tsa_ByAxisValue" AxisType="at_Standard"> <fields> <field name="SaleDate" caption="SaleDate" alignment="taLeftJustify" captionwidth="100" field_name="SaleDate" SortDirection="fcsd_Asc" TotalPosition="fctp_Before" UseTotalPositionFromMeasure="False"> <AdditionalTotals/> </field> </fields> <AdditionalGrandTotals/> </yaxis_fields> <measure_fields alignment="taLeftJustify" caption="Measures" CaptionWidth="100" Region="X" Position="0"> <fields> <field name="Qty" caption="Qty" alignment="taRightJustify" captionwidth="100" field_name="Qty" field2_name="Qty" fieldadv_name="Qty" AgrFunc="af_Sum" Visible="True" DisplayAs="da_Value" CalcAllCells="False" CalcAllCellsForTotals="False" Distinct="False" ChangeNullToZero="False" DefaultTotalPosition="fctp_After" UseDifferentAggForTotals="False" AgrFuncForTotals="af_Sum" CalcTotalsOnTotals="False" UseXAxisTotalsAsBase="False"> <display_format Version="2" Name="General"/> <HIGHLIGHTS/> </field> </fields> </measure_fields> <topn/> <selection col="0" row="0" measure="0"/> <sortselection xlevelindex="0" xindexinlevel="0" xmeasureindex="0" xadditionaltotalindex="0" ylevelindex="0" yindexinlevel="0" ymeasureindex="0" yadditionaltotalindex="0"/> <options HideColZeros="False" HideRowZeros="False"/> <groups version="2" timestamp="12.05.2017 16:31:09"/> <filters version="2" timestamp="12.05.2017 16:31:09"/> <charts version="2" timestamp="12.05.2017 16:31:09"> <chart_properties TypeChartData="tcd_ByAxisMeasures" CategoriesAxis="ar_RowAxis" SeriesAxis="ar_ColAxis" CategoriesFieldCount="1" SeriesFieldCount="1" MeasureFieldIndex="0" MarksShowStyle="ssNone" SkipNullPoints="False" Legend_Visible="True"/> </charts> </slice>
這是一個(gè)簡(jiǎn)單的XML文件,從數(shù)據(jù)庫(kù)中獲取的字段在部分中聲明,部分包含將在X軸上顯示的字段。類似地,僅針對(duì)Y軸的部分是相同的,X軸和Y軸都包含測(cè)量字段,具體取決于多維數(shù)據(jù)的方向,部分包含字段度量。文本將此方案加載到多維數(shù)據(jù)集中,并使用數(shù)據(jù)庫(kù)中的數(shù)據(jù)填充它。具體操作如下所示:創(chuàng)建一個(gè)WindowsForms應(yīng)用程序,在項(xiàng)目引用中添加庫(kù):FastReport.Olap,F(xiàn)astReport.Bars,在安裝了FastCube.Net的文件夾中找到:“C:\ Program Files(x86)\ FastReports \ FastCube.Net Professional”。然后將以下組件“拖”到工具箱中的表單:cube,dataSource,dbDataSet,slice,sliceGrid,oleDbConnection,oleDbCommand。
配置所有這些組件,連接到數(shù)據(jù)庫(kù):在oleDbConnection1屬性中,將ConnectionString值設(shè)置為“Provider = Microsoft.Jet.OLEDB.4.0; Data Source =”C:\ Program Files(x86)\ FastReports \ FastCube.Net Professional \ demo.mdb“。繼續(xù)執(zhí)行組件oleDbCommand1,在其CommandText屬性中,編寫以下SQL查詢:
SELECT items.OrderNo, items.PartNo, items.Qty, orders.CustNo, orders.EmpNo, orders.SaleDate FROM (items LEFT OUTER JOIN orders ON items.OrderNo = orders.OrderNo) WHERE (items.OrderNo < 1100)
對(duì)于dbDataSet1組件,設(shè)置DbCommand屬性— oleDBCommand1;DataSource1,選擇DataSet— dbDataSet1;配置cube1,選擇DataSource —DataSource1,SourceType是一個(gè)DataSource。對(duì)于slice1組件,只需要設(shè)置一個(gè)屬性— cube(多維數(shù)據(jù)集),sliceGrid1組件是添加的唯一可視組件:
設(shè)置slice-slice1,為表單創(chuàng)建一個(gè)OnLoad事件處理程序:
并添加以下代碼:
private void Form1_Load(object sender, EventArgs e) { string filePath = "J:/Program Files (x86)/FastReports/FastCube.Net Professional/Demos/Data/Cubes/dataset_en1.mds"; cube1.Load(filePath); cube1.Active = true; slice1.Load(filePath); }
加載一個(gè)多維數(shù)據(jù)和一個(gè)切片,必須激活多維數(shù)據(jù)集,以便從數(shù)據(jù)庫(kù)加載數(shù)據(jù)。現(xiàn)在啟動(dòng)應(yīng)用程序:
因此,將多維數(shù)據(jù)集連接到數(shù)據(jù)庫(kù)并不困難,可以通過手動(dòng)創(chuàng)建跨表視圖(通過拖動(dòng)字段并使用鼠標(biāo)進(jìn)行其他設(shè)置),然后使用slice.Save()方法或單擊“保存”來保存帶有方案的mds文件, “交叉標(biāo)簽toolbar.scheme上的”按鈕
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn