| BUG: Binding Hierarchical Recordset in Data EnvironmentID: Q190605 
 | 
In Data Environment, when a hierarchical recordset is used, and the parent/child/grandchild recordsets are bound, the expected behavior is for all the child/grandchild recordsets to "stay in sync" with the parent. However, when record in the parent table moves, the grandchild recordset does not receive notification that it needs to retrieve the current chapter. This creates a situation in which the grandchild recordset becomes out of sync.
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.
The following Visual Basic code reproduces the problem described above.
Access database NWIND.MDB is used here: Customers table is the parent,
Orders table, the child, and OrderDetails table, the grandchild. Two
workarounds are provided by binding the parent/child/grandchild recordsets
in code to the DataGrid controls. Workaround 1 takes the recordset from the
Data Environment, and sets the DataSource property with the recordsets;
Workaround 2, bypassing the Data Environment, uses the ADO SHAPE command to
generate the hierarchical recordset.
   Property     Value
   ----------------------
   CommandText  Customers
   CommandType  adCmdTable
 
      Option Explicit
      Dim cn as ADODB.Connection
      Dim rsCustomers As ADODB.Recordset
      Dim rsOrders As ADODB.Recordset
      Dim rsOrderDetails As ADODB.Recordset
      Private Sub Form_Load()
         Command1.Caption = "Re-pro"
         Command2.Caption = "Workaround I"
         Command3.Caption = "Workaround II"
      End Sub
      Private Sub Command1_Click()
         Set DataGrid1.DataSource = DataEnvironment1
         DataGrid1.DataMember = "Customers"
         Set DataGrid2.DataSource = DataEnvironment1
         DataGrid2.DataMember = "Orders"
         Set DataGrid3.DataSource = DataEnvironment1
         DataGrid3.DataMember = "OrderDetails"
      End Sub
      Private Sub Command2_Click()
         Set DataGrid1.DataSource = Nothing
         DataGrid1.DataMember = ""
         Set DataGrid2.DataSource = Nothing
         DataGrid2.DataMember = ""
         Set DataGrid3.DataSource = Nothing
         DataGrid3.DataMember = ""
         Set rsCustomers = DataEnvironment1.rsCustomers
         Set rsOrders = rsCustomers.Fields("Orders").Value
         Set rsOrderDetails = rsOrders.Fields("OrderDetails").Value
         Set DataGrid1.DataSource = rsCustomers
         Set DataGrid2.DataSource = rsOrders
         Set DataGrid3.DataSource = rsOrderDetails
      End Sub
      Private Sub Command3_Click()
         Dim cn As New ADODB.Connection
         With cn
            .Provider = "MSDataShape"
            .CursorLocation = adUseClient
            .ConnectionString = "dsn=nwind;"
            .Open
         End With
         Dim rsCustomers As New ADODB.Recordset
         Dim rsOrders As ADODB.Recordset
         Dim rsOrderDetails As ADODB.Recordset
         rsCustomers.Source = "SHAPE {SELECT * FROM Customers} " & _
                             "APPEND ((SHAPE {SELECT * FROM Orders} " & _
                             "AS Orders " & _
                             "APPEND ({SELECT * FROM [Order Details]} " & _
                             "AS OrderDetails " & _
                             "RELATE OrderID TO OrderID)) " & _
                             "AS Orders RELATE CustomerID TO CustomerID)"
        rsCustomers.Open , cn, adOpenStatic, adLockOptimistic
        Set rsOrders = rsCustomers.Fields("Orders").Value
        Set rsOrderDetails = rsOrders.Fields("OrderDetails").Value
        Set DataGrid1.DataSource = Nothing
        DataGrid1.DataMember = ""
        Set DataGrid2.DataSource = Nothing
        DataGrid2.DataMember = ""
        Set DataGrid3.DataSource = Nothing
        DataGrid3.DataMember = ""
        Set DataGrid1.DataSource = rsCustomers
        Set DataGrid2.DataSource = rsOrders
        Set DataGrid3.DataSource = rsOrderDetails
      End Sub
 
For additional information on SHAPE APPEND syntax and how to traverse
hierarchical recordsets, please see the following articles in the Microsoft
Knowledge Base:
Q189657 : HOWTO: Use the ADO SHAPE Command
Q185425 : ADO Hierarchical Recordsets via SHAPE APPEND via C++/VBA/Java
Additional query words: kbADO kbDatabase kbDataBinding kbdse kbDSupport kbVBp600bug
Keywords          : 
Version           : 
Platform          : WINDOWS 
Issue type        : kbbug Last Reviewed: May 21, 1999