對于手動填充或從數(shù)據(jù)庫填充的多維數(shù)據(jù)集,還需要創(chuàng)建或加載其表示,例如:可以從mds文件加載現(xiàn)成的表示,在本文中將介紹將多維數(shù)據(jù)集連接到數(shù)據(jù)庫的方法。
帶有數(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>這是一個簡單的XML文件,從數(shù)據(jù)庫中獲取的字段在部分中聲明,部分包含將在X軸上顯示的字段。類似地,僅針對Y軸的部分是相同的,X軸和Y軸都包含測量字段,具體取決于多維數(shù)據(jù)的方向,部分包含字段度量。文本將此方案加載到多維數(shù)據(jù)集中,并使用數(shù)據(jù)庫中的數(shù)據(jù)填充它。具體操作如下所示:創(chuàng)建一個WindowsForms應(yīng)用程序,在項目引用中添加庫:Fa,F(xiàn)a,在安裝了Fa的文件夾中找到:“C: Program Files(x86) FastReports Fa Professional”。然后將以下組件“拖”到工具箱中的表單:cube,dataSource,dbDataSet,slice,sliceGrid,oleDbConnection,oleDbCommand。
配置所有這些組件,連接到數(shù)據(jù)庫:在oleDbConnection1屬性中,將ConnectionString值設(shè)置為“Provider = Micro; Data Source =”C: Program Files(x86) FastReports Fa Professional demo.mdb“。繼續(xù)執(zhí)行組件oleDbCommand1,在其CommandText屬性中,編寫以下SQL查詢:
SELECT i, i, i, orders.CustNo, orders.EmpNo, orders.SaleDate FROM (items LEFT OUTER JOIN orders ON i = orders.OrderNo) WHERE (i < 1100)對于dbDataSet1組件,設(shè)置DbCommand屬性— oleDBCommand1;DataSource1,選擇DataSet— dbDataSet1;配置cube1,選擇DataSource —DataSource1,SourceType是一個DataSource。對于slice1組件,只需要設(shè)置一個屬性— cube(多維數(shù)據(jù)集),sliceGrid1組件是添加的唯一可視組件:
設(shè)置slice-slice1,為表單創(chuàng)建一個OnLoad事件處理程序:
并添加以下代碼:
private void Form1_Load(object sender, EventArgs e) { string filePath = "J:/Program Files (x86)/FastReports/Fa Professional/Demos/Data/Cube;; cube1.Load(filePath); cube1.Active = true; (filePath); }加載一個多維數(shù)據(jù)和一個切片,必須激活多維數(shù)據(jù)集,以便從數(shù)據(jù)庫加載數(shù)據(jù)?,F(xiàn)在啟動應(yīng)用程序:
因此,將多維數(shù)據(jù)集連接到數(shù)據(jù)庫并不困難,可以通過手動創(chuàng)建跨表視圖(通過拖動字段并使用鼠標進行其他設(shè)置),然后使用()方法或單擊“保存”來保存帶有方案的mds文件, “交叉標簽上的”按鈕
1.《.net如何連接數(shù)據(jù)庫看這里!「FastCube.Net教程」如何將數(shù)據(jù)庫連接到多維數(shù)據(jù)集》援引自互聯(lián)網(wǎng),旨在傳遞更多網(wǎng)絡(luò)信息知識,僅代表作者本人觀點,與本網(wǎng)站無關(guān),侵刪請聯(lián)系頁腳下方聯(lián)系方式。
2.《.net如何連接數(shù)據(jù)庫看這里!「FastCube.Net教程」如何將數(shù)據(jù)庫連接到多維數(shù)據(jù)集》僅供讀者參考,本網(wǎng)站未對該內(nèi)容進行證實,對其原創(chuàng)性、真實性、完整性、及時性不作任何保證。
3.文章轉(zhuǎn)載時請保留本站內(nèi)容來源地址,http://f99ss.com/gl/2091854.html