We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Get data from CurrentCellSet

Hi,

I have two questions;

a) I'm woundering if it is possible to 'get the data' out from a CurrenctCellSet.
I would like to use the OLAP Base classes etc to execute a MDX request to a cube, but the CellSet comming back, I would like to be able to push into some other visualization components and reports.

b) Is it possible to in one way or another load relational data to the BI OLAP Grid using an ItemSource or similar. If yes - do you have some code example or similar?
/Erik

5 Replies

AG Anish George Syncfusion Team June 20, 2013 10:31 AM UTC

Hi Erik,

 

Thanks for using Syncfusion products.

 

a)      Yes we can get the data from a CurrentCellSet. Please refer the below code snippet.

            OlapDataManager manager = new OlapDataManager("datasource =    D:\\DB\\Adventure_Works_Ext.cub; Provider = MSOLAP");

            manager.MdxQuery = " SELECT   NONEMPTY({[Measures].[Reseller Sales Amount]})  dimension properties MEMBER_TYPE, PARENT_UNIQUE_NAME  ON COLUMNS ,    NONEMPTY( VISUALTOTALS(      ({{Drilldownlevel({ [Date].[Fiscal] })}}) ),{[Measures].[Reseller Sales Amount]})  dimension properties MEMBER_TYPE, PARENT_UNIQUE_NAME  ON ROWS  FROM [Adventure Works]  CELL PROPERTIES VALUE,   FORMAT_STRING, FORMATTED_VALUE";

            manager.ExecuteCellSet();

            CellSet currentdata;

            currentdata = manager.CurrentCellSet;

            PivotEngine _engine;

           _engine = manager.ExecuteOlapTable(currentdata);

 

In the above code snippet you can get the data from the PivotEngine ( _engine ).

 

 

b)      Yes we can load Relational Data in OlapGrid. We have created a simple sample for your convenience. You can download it from the below link.

http://www.syncfusion.com/downloads/Support/DirectTrac/General/RelationalDataBinding1129045690.zip

 

 

Please let us know if you have any further concerns.

 

Regards,

Anish.



EL Erik Lidman June 30, 2013 08:30 PM UTC

Perfekt,
Worked greate to get the data. Thanx,
/Erik

 DataListBox.Items.Clear();

            CellSet currentdata;
            currentdata = olapDataManager.CurrentCellSet;

            PivotEngine _engine;
            //_engine = olapDataManager.ExecuteOlapTable(currentdata);  //if manual mdx is executed and not a "report"

            _engine = olapDataManager.PivotEngine;  //if hooking into the current olapDataManager PivotEngine directly (ie. - no need to define a new _engine)


            int rows = _engine.RowsCount;
            int col = _engine.TableColumns.Count;

            //foreach (var column in _engine.TableColumns)
            //{
            //    // Do something

            //}


            // Get all data from the PivotEngine
            for (int i = 0; i < rows; i++)
            {

                var rowcollection = _engine.GetRowAt(i);

                foreach (var cell in rowcollection.Cells)
                {

                    //Populate DataListBox with columnheaders
                    if (cell.CellType == PivotCellDescriptorType.ColumnHeader)
                    {
                        DataListBox.Items.Add("ColumnHeader:" + cell.CellValue.ToString());
                    }

                    //Populate DataListBox with rowheaders
                    if (cell.CellType == PivotCellDescriptorType.RowHeader)
                    {
                        DataListBox.Items.Add("RowHeader:" + cell.CellValue.ToString());
                    }

                    //Populate DataListBox with cell values
                    if (cell.CellType == PivotCellDescriptorType.Value)
                    {
                        DataListBox.Items.Add("Value:" + cell.CellValue.ToString());
                    }



JA Jesus Arockia Sankaran S Syncfusion Team July 1, 2013 12:34 PM UTC

Hi,

Thanks for your update.

Regards,
Jesus Arockia Sankaran S



EL Erik Lidman July 1, 2013 09:47 PM UTC

Hi,
Now I try to connect to relational data in my own project (your example works fine, but I have problems following what you have been doing).
The code below is what I try to do.
I get an "Object reference not set to an instance of an object." error when I try to connect the olapDataManager to the Grid on line: MyOlapGrid.OlapDataManager = olapDataManager;

What can be wrong?
I also attach the stacktrace.
/Erik


public partial class MainWindow : Window
    {
        DataTable dataTable;

        public MainWindow()
        {
            InitializeComponent();
        }

        private void GetDataButton_Click(object sender, RoutedEventArgs e)
        {
            //Load data into datatable using a select statement in GetData()
            dataTable = null;
            dataTable = GetData();
            MessageBox.Show(dataTable.Rows.Count.ToString() + " rows loaded into memory");
        }

        private void PopGridButton_Click(object sender, RoutedEventArgs e)
        {
            //Create a new olapDataManager
            OlapDataManager olapDataManager = new OlapDataManager();

            //Assign a relational "dataTable" as the ItemSource
            olapDataManager.ItemSource = dataTable;
            //Configure the report definition (columns, rows and measures)
            olapDataManager.SetCurrentReport(CreateRelationalReport());
            
            //Connect the olapDataManager to the OlapGrid           
            MyOlapGrid.OlapDataManager = olapDataManager;  //Here I get the error "Object reference not set to an instance of an object."

            //Force the grid to DataBind
            MyOlapGrid.DataBind();

        }

        private static DataTable GetData()
        {
            SqlConnection myConnection = new SqlConnection("Server = ERLIW8; Database = PerformanceTest3; Trusted_Connection = True;");
            myConnection.Open();
            SqlDataReader myReader = null;
            SqlCommand myCommand = new SqlCommand("select * from dbo.test", myConnection);
            myReader = myCommand.ExecuteReader();
            DataTable selectTable = new DataTable();
            selectTable.Load(myReader);
            return selectTable;
        }

        private OlapReport CreateRelationalReport()
        {
            OlapReport olapReport = new OlapReport();
                
            DimensionElement dimensionElementRow = new DimensionElement();
            dimensionElementRow.Name = "dim1";
            dimensionElementRow.Hierarchy = new HierarchyElement() { Name = "dim1" };

            // Specifying the Column Dimension Element
            DimensionElement dimensionElementColumn = new DimensionElement();
            dimensionElementColumn.Name = "dim2";
            dimensionElementColumn.Hierarchy = new HierarchyElement() { Name = "dim2" };

            // Specifying the Summary Elements
            SummaryElements summaries = new SummaryElements();
            summaries.Add(new SummaryInfo { Column = "amount", Key = "amount", Type = SummaryType.Sum });
            
            // Adding the Row Elements
            olapReport.SeriesElements.Add(new Item { ElementValue = summaries });
            olapReport.SeriesElements.Add(new Item { ElementValue = dimensionElementRow });
            // Adding the Column Elements
            olapReport.CategoricalElements.Add(new Item { ElementValue = dimensionElementColumn });
            return olapReport;
        }
    }

---Stacktrace---
System.NullReferenceException was unhandled
  HResult=-2147467261
  Message=Object reference not set to an instance of an object.
  Source=Syncfusion.Olap.Base
  StackTrace:
       at Syncfusion.Olap.Engine.Extension.PivotExtension.<GroupBy>d__11.MoveNext()
       at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
       at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
       at Syncfusion.Olap.Engine.TableBuilder.BuildEngineFromIListSource(IListSource listSource, OlapReport CurrentReport, SortType sortOrder, String[] columnGroup, String[] rowGroup, SummaryInfo[] summaryInfos, Boolean isRowSummary, GridLayout layout, Boolean ExpandAll, Int32 summaryStringCount, PivotCellDescriptor drilledCell, Boolean drillDown)
       at Syncfusion.Olap.Manager.OlapDataManager.ExecuteOlapTable(GridLayout layout)
       at Syncfusion.Windows.Grid.Olap.OlapGridBase.DataBind()
       at Syncfusion.Windows.Grid.Olap.OlapGrid.OnOlapDataManagerChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
       at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
       at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
       at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
       at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
       at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
       at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
       at SyncfusionWPF.MainWindow.PopGridButton_Click(Object sender, RoutedEventArgs e) in d:\Dropbox\3 Development\Analytics\RelationalPivoting\Syncfusion\SyncfusionWPFRelational\SyncfusionWPF\MainWindow.xaml.cs:line 58
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.Controls.Button.OnClick()
       at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
       at System.Windows.Input.InputManager.ProcessStagingArea()
       at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
       at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
       at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       at System.Windows.Application.RunInternal(Window window)
       at System.Windows.Application.Run()
       at SyncfusionWPF.App.Main() in d:\Dropbox\3 Development\Analytics\RelationalPivoting\Syncfusion\SyncfusionWPFRelational\SyncfusionWPF\obj\Debug\App.g.cs:line 0
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 


JA Jesus Arockia Sankaran S Syncfusion Team July 2, 2013 11:56 AM UTC

Hi Erik,

 

We would like to inform you that, we have excellent support for relational data binding in Pivot Grid, also we appreciate you to utilize our Pivot Grid control for relational data binding.

 

Please let me know if you have any queries.

 

Regards,

Jesus Arockia Sankaran S



CS_bc604059.zip

Loader.
Live Chat Icon For mobile
Up arrow icon