0

I have a DataTable that is populated by an MDX query. I want to bind that DataTable to a GridView and show all data that is returned. My GridView is defined like this:

<asp:GridView ID = "gvResults" runat="server" AutoGenerateColumns="true" />

MDX query is called as follows:

DataTable mdxResults = new DataTable();
CellSet cellSet;

AdomdCommand command = new AdomdCommand();

strCommand = "SELECT NON EMPTY({[Measures].[Assets Distinct Count], [Measures].[Value]}) " + 
"ON COLUMNS, NONEMPTY({[Organization].[Org Id].[Org Id]*[Location].[Loc Id].[Loc Id]}) " + 
"ON ROWS FROM [database]"

command.Connection = _CurrentConnection;
command.CommandText = strCommand;
cellSet = command.ExecuteCellSet();
AdomdDataAdapter dataAdapter = new AdomdDataAdapter(command);
objDataAdapter.Fill(mdxResults);

An example of a DataTable that could be produced from the MDX query:

Organization   Location      Assets     Value
Org A          Los Angeles   12         320000
Org B          San Jose      6          21000

Assets and Value are aggregated measures from the MDX query.

The DataTable is then bound to the GridView after I rename columns:

gvResults.DataSource = mdxResults;
gvResults.DataBind();

After I bind the DataTable only a subset of the columns display in the GridView. Specifically, all columns but the Measure columns from the MDX query will display.

Any help would be appreciated.

user2623855
  • 93
  • 1
  • 3
  • 16

1 Answers1

1

The issue ended up being that the MDX query would fill the DataTable with type Object for the Measure results which is not supported by AutoGenerateColumns. To correct this I utilized the solution here to change the DataType before binding to the GridView: How To Change DataType of a DataColumn in a DataTable?

Community
  • 1
  • 1
user2623855
  • 93
  • 1
  • 3
  • 16