【发布时间】:2014-11-28 13:31:04
【问题描述】:
我有一个由 MDX 查询填充的 DataTable。我想将该 DataTable 绑定到 GridView 并显示返回的所有数据。我的 GridView 是这样定义的:
<asp:GridView ID = "gvResults" runat="server" AutoGenerateColumns="true" />
MDX 查询调用如下:
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);
可以从 MDX 查询生成的 DataTable 示例:
Organization Location Assets Value
Org A Los Angeles 12 320000
Org B San Jose 6 21000
Assets 和 Value 是来自 MDX 查询的聚合度量。
重命名列后,DataTable 将绑定到 GridView:
gvResults.DataSource = mdxResults;
gvResults.DataBind();
在我绑定 DataTable 后,GridView 中只显示列的一个子集。具体来说,将显示除 MDX 查询中的 Measure 列之外的所有列。
任何帮助将不胜感激。
【问题讨论】:
-
插入其余的 GridView 代码和 DataTable 示例
-
能否显示调用查询的代码,然后将 DataTable 的结果绑定到 Gridview..?