Hello,
I am trying to display data from a mdx query in a datagrid with wpf and mvvm.
here is my xaml:
<DataGrid AutoGenerateColumns="True"
ItemsSource="{Binding ResultTable}"
Height="300"
MinWidth="600"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.CanContentScroll="True"></DataGrid>
My viewModel:
private DataTable _resultTable;
public DataTable ResultTable
{
get { return _resultTable; }
set
{
_resultTable = value;
OnPropertyChanged(() => ResultTable);
}
}
public void ToDataTable(string query)
{
DataSet DS = new DataSet();
DataTable DT = null;
AdomdDataAdapter DA;
string tname = "T1";
try
{
DA = new AdomdDataAdapter(query, Connection);
DA.Fill(DS, tname);
if (DS != null)
{
if (DS.Tables.Contains(tname))
{
ResultTable= DS.Tables[tname];
}
}
}
catch (AdomdException ex1)
{
DT = null;
throw ex1;
}
catch (Exception ex)
{
DT = null;
throw ex;
}
}
I get this exception :
System.Windows.Data Error: 17 : Cannot get 'Item[]' value (type 'Object') from '' (type 'DataRowView'). BindingExpression:Path=[Artículos].[Artículo].[Artículo].[MEMBER_CAPTION]; DataItem='DataRowView' (HashCode=57334574); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String') TargetInvocationException:'System.Reflection.TargetInvocationException: Se produjo una excepción en el destino de la invocación. ---> System.ArgumentException: Artículos no es DataColumn ni DataRelation para la tabla T1.
en System.Data.DataRowView.get_Item(String property)
And my query is :
SELECT NON EMPTY { [Measures].[%Importe] } ON COLUMNS ,
NON EMPTY { [Artículos].[Artículo].ALLMEMBERS * [Artículos].[Familia].ALLMEMBERS } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS
FROM [Modelo] CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
The result:
I show the one from my solution and the other from SqlServer2012 analysis services
Snapshot
What am I missing in the process? Any other way of displaying the data automatically?