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;
I also attach the stacktrace.
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;
}
}
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: