Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. Imports Microsoft.AnalysisServices.AdomdClient
  2. Public Class Form1
  3. Dim matrix(0, 0) As String
  4. Dim noLines, noCols As Integer
  5. Dim conn As New AdomdConnection("Provider=SQLNCLI11.1;Data Source=MV-W81-32BITS;" & _
  6. "Integrated Security=SSPI;Initial Catalog=L1")
  7. Dim cmd As AdomdCommand
  8.  
  9.  
  10. Private Sub connect()
  11. conn.Open()
  12.  
  13. cmd = New AdomdCommand("SELECT NON EMPTY [Order Date].[All].Children ON rows," & _
  14. " NON EMPTY [Dim Product].[All].children ON columns FROM [Adventure Works DW2012-cube]" & _
  15. " WHERE [Measures].[Sales Amount]")
  16. cmd.Connection = conn
  17. Dim cs As CellSet
  18.  
  19. cs = cmd.ExecuteCellSet
  20. noCols = cs.Axes(0).Positions.Count
  21. noLines = cs.Axes(1).Positions.Count
  22. ReDim matrix(noCols, noLines)
  23. matrix(0, 0) = ""
  24. Dim axis As Axis
  25. For i = 0 To noCols - 1
  26. matrix(0, i + 1) = cs.Axes(0).Positions(i).Members(0).Caption
  27. axis = cs.Axes(1)
  28. For j = 0 To noLines - 1
  29. matrix(j + 1, 0) = axis.Positions(j).Members(0).Caption
  30. matrix(j + 1, i + 1) = Math.Round(cs(i, j).Value, 2, MidpointRounding.AwayFromZero)
  31. Next
  32. Next
  33.  
  34. conn.Close()
  35. End Sub
  36.  
  37. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  38. DataGridView1.DataSource = Nothing
  39. DataGridView1.DataSource = CreateDataView(matrix, noLines, noCols)
  40. End Sub
  41.  
  42. Function CreateDataView(matrix As Array, noLines As Integer, noCols As Integer) As ICollection
  43. Dim dt As New DataTable()
  44. Dim dr As DataRow
  45. If matrix.Length > 1 Then
  46. dt.Columns.Add(New DataColumn("Year", GetType(String)))
  47. Dim k, l As Integer
  48. For k = 0 To noCols - 1
  49. dt.Columns.Add(New DataColumn(matrix(0, k + 1), GetType(String)))
  50. Next
  51. For l = 1 To noLines
  52. dr = dt.NewRow()
  53. For k = 0 To noCols
  54. dr(k) = matrix(l, k)
  55. Next
  56. dt.Rows.Add(dr)
  57. Next
  58. End If
  59. Dim dv As New DataView(dt)
  60. Return dv
  61. End Function
  62.  
  63. Private Sub Form1_Load_1(sender As Object, e As EventArgs) Handles MyBase.Load
  64. connect()
  65. End Sub
  66.  
  67. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  68. Chart1.Series.Clear()
  69. For k = 1 To noCols
  70. Chart1.Series.Add(matrix(0, k))
  71. Next
  72. For l = 1 To noLines
  73. For k = 1 To noCols
  74. Chart1.Series(matrix(0, k)).Points.AddXY(matrix(l, 0), matrix(l, k))
  75. Next
  76. Next
  77. End Sub
  78. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement