共用方式為


產生階層式資料錄集

下列範例示範如何使用資料成形文法來定義父系、子系和孫系 Recordets 的資料行,產生沒有基礎資料來源的階層式 Recordset。

若要產生階層式 Recordset,您必須指定 Microsoft Data Shaping Service for OLE DB (ADO Service Provider) (MSDataShape),而且您可以在 Connection 物件的 Open 方法的連接字串參數中,將資料提供者值指定為 NONE。 如需詳細資訊,請參閱資料成形的必要提供者

Dim cn As New ADODB.Connection  
Dim rsCustomers As New ADODB.Recordset  
  
cn.Open "Provider=MSDataShape;Data Provider=NONE;"  
  
strShape = _  
"SHAPE APPEND NEW adInteger AS CustID," & _  
            " NEW adChar(25) AS FirstName," & _  
            " NEW adChar(25) AS LastName," & _  
            " NEW adChar(12) AS SSN," & _  
            " NEW adChar(50) AS Address," & _  
         " ((SHAPE APPEND NEW adChar(80) AS VIN_NO," & _  
                        " NEW adInteger AS CustID," & _  
                        " NEW adChar(20) AS BodyColor, " & _  
                     " ((SHAPE APPEND NEW adChar(80) AS VIN_NO," & _  
                                    " NEW adChar(20) AS Make, " & _  
                                    " NEW adChar(20) AS Model," & _  
                                    " NEW adChar(4) AS Year) " & _  
                        " AS VINS RELATE VIN_NO TO VIN_NO))" & _  
            " AS Vehicles RELATE CustID TO CustID) "  
  
rsCustomers.Open strShape, cn, adOpenStatic, adLockOptimistic, -1  

一旦 Recordset 產生,就可以填入、操作或保存至檔案。

另請參閱

存取階層式資料錄集中的資料列
正式 Shape 文法
資料成形所需的提供者
Shape APPEND 子句
一般 Shape 命令