DataReader中的多维MDX查询

时间:2016-05-25 10:09:43

标签: sql-server vb.net mdx adomd.net

请参阅以下代码:

 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load

        Try
            Dim con As AdomdConnection = New AdomdConnection("Data Source=localhost;Catalog=Analysis Services Tutorial")

            Dim commandText As String = "select {[Measures].[Sales Amount] AS SalesAmount, [Measures].[Currency Key] as CurrencyKey } On COLUMNS, " & _
    "{[Customer].[Full Name].Members} ON Rows " & _
    ",{[Customer].[Birth Date].Members} ON Pages " & _
    "FROM [Adventure Works DW2012] "

            Dim cmd As AdomdCommand = New AdomdCommand(commandText, con)
            con.Open()
            Dim objDR As AdomdDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)

            Dim strBuilder As New StringBuilder
            strBuilder.Append("<table>")
            strBuilder.Append("<tr><th>Birth Date</th><th>Full Name</th><th>Currency Key</th><th>Sales Amount</th></tr>")
            Dim intCount As Integer = 0
            While (objDR.Read())
                intCount = intCount + 1
                If intCount = 10 Then
                    Exit While
                Else
                    strBuilder.Append("<tr>")
                    strBuilder.Append("<td>" & objDR(0) & "</td>")
                    strBuilder.Append("<td>" & objDR(1) & "</td>")
                    strBuilder.Append("<td>" & objDR(2) & "</td>")
                    strBuilder.Append("<td>" & objDR(3) & "</td>")
                    strBuilder.Append("</tr>")
                End If
            End While
            strBuilder.Append("</table>")
            Dim str As String = strBuilder.ToString
            MsgBox("got here")

        Catch ex As Exception
            Console.Write(ex.ToString)
        End Try
    End Sub

输出如下:

enter image description here

似乎ADOMD.NET可以处理多维查询,但结果是平坦的。这是对的吗?

我问的原因是因为我在这里读了几个问题,这表明ADOMD.NET只能显示二维查询。

1 个答案:

答案 0 :(得分:1)

正确。 ADOMD.net只会以表格格式检索数据。

  

当命令运行查询时,ADOMD.NET将返回结果   结果集格式,XML格式中描述的表格格式   分析规范,用于展平AdomdDataReader的数据   宾语。查询分析数据时,表格格式不常见   考虑这些数据中的变量维数。

Retrieving Data from the AdomdDataReader