Visual Basic 的資料成形範例
' This application makes use of Microsoft Hierarchical FlexGrid
' Control, which is named as MSHFLexGrid.
Const SHAPER = "MSDataShape"
Const DP = "SQLOLEDB"
Const DS = "MySQLServer"
Const DB = "Northwind"
Private Sub Form_Load()
FirstExample
End Sub
Private Sub Form_Resize()
MSHFlexGrid.Top = 0
MSHFlexGrid.Left = 0
MSHFlexGrid.Width = Me.ScaleWidth
MSHFlexGrid.Height = Me.ScaleHeight
End Sub
Private Sub FirstExample()
Dim con As ADODB.Connection
Dim rst As ADODB.Recordset
Dim sCmd As String
Set con = New ADODB.Connection
Set rst = New ADODB.Recordset
con.ConnectionString = ConnectionString(SHAPER, DP, DS, DB)
con.Open
sCmd = "SHAPE {SELECT CustomerID, ContactName FROM Customers} " _
& "APPEND ({SELECT OrderID, OrderDate, CustomerID FROM Orders} " _
& "AS chapOrders " _
& "RELATE customerID TO customerID)"
rst.Open sCmd, con, adOpenStatic, 2
Set MSHFlexGrid.Recordset = rst
rst.Close
Set rst = Nothing
con.Close
Set con = Nothing
End Sub
Private Function ConnectionString(pr As String, _
dpr As String, _
dsr As String, _
dbs As String)
Dim s As String
If pr = "" Then
s = "Provider=" & dpr & _
";Data Source=" & dsr & _
";Initial Catalog=" & dbs & _
";Integrated Security=SSPI;"
Else
s = "Provider=" & pr & _
";Data Provider=" & dpr & _
";Data Source=" & dsr & _
";Initial Catalog=" & dbs & _
";Integrated Security=SSPI;"
End If
ConnectionString = s
End Function
請嘗試
建立 Visual Basic Standard EXE 應用程式專案
從 Visual Studio 中的 [專案]功能表選取 [元件]
從 [元件] 快顯視窗中選取 [Microsoft 階層式 FlexGrid 控制項 6.0 (OLEDB)],然後按一下 [儲存]。
在 Visual Basic 工作區的 [ToolBox] 窗格中按兩下 FlexGrid 控制項。 將此執行個體的名稱變更為 MSHFLEXGRID。
複製上述程式碼,並將其貼到 [程式碼] 頁面中,以取代任何現有的程式碼。
從 [執行] 功能表中選取 [開始] 以執行應用程式。