Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Nov 22, 2010 01:31 AM by decker dong - msft
Nov 18, 2010 10:24 PM|LINK
I'm a novice trying to display the results of an MDX query. The following code is in the Page_Load:
strCommand = "valid mdx query";
sConnString="valid connection string";
objConnection = new AdomdConnection(sConnString);
objCommand = new AdomdCommand(strCommand, objConnection);
objCellSet = objCommand.ExecuteCellSet();
GridView1.DataSource = getDataTable(objCellSet);
The function getDataTable() is based on the code found here (translated into C#): http://asmdx.blogspot.com/2008_05_01_archive.html
The GridView is just a simple GridView: <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns=true></asp:GridView>
The result of the query I'm testing with should be in 5 columns. All of the information is displayed, but the first three columns are crammed into one.
...And so on. Those two letters after the date should each be in their own column. Also, the first column is always "Description". This comes from the implementation of the code, and I can't figure out how to make that first column dependent on the query
instead of what is hard coded.
I was also trying another method to bind the data:
AdomdConnection conn = new AdomdConnection("connection string");
AdomdCommand cmd = new AdomdCommand("MDX query");
DataTable dt = new DataTable();
AdomdDataAdapter myDataAdapter =new AdomdDataAdapter(cmd);
GridView1.DataSource = dt;
This time, it displays the first three columns correctly (the three that the first method crammed into one column), but does not display the last two columns at all. This method is also inferior because instead of displaying nice column names it displays
part of the query.
Do these three good columns have something to do with the three columns displayed in the design view? Where are these columns coming from and how can I get more of them?
Alternatively, is there an easier way to display this data that I'm missing?
Nov 19, 2010 09:42 AM|LINK
Nov 22, 2010 01:31 AM|LINK
How did you design your Columns of the GridView?
If you confirm that you really have five columns in the DataTable, please set
the property of Gridview "AutoGeneratedColumn=true" and have a try.