Wrox Home  
Search P2P Archive for: Go

  Return to Index  

activex_data_objects thread: Hierarchical recordsets with 3+ levels


Message #1 by "Neil Dutton" <N.Dutton@d...> on Mon, 8 Apr 2002 22:01:26
I have created a parent-child hierarchical recordset in code using the 
SHAPE APPEND NEW command and populated it with data (as shown below)


'Start of original code
strConn = "Provider=MSDataShape; Data Provider=none"
Set objConn = New ADODB.Connection
objConn.Open strConn

strShape = "SHAPE APPEND NEW adChar(4) AS pub_id, NEW adVarChar(40) AS 
pub_name, NEW adVarChar(20) AS city, "
strShape = strShape & "NEW adChar(2) AS State, NEW adVarChar(30) AS 
country, ((SHAPE APPEND NEW adVarChar(6) AS title_id, "
strShape = strShape & "NEW adVarChar(80) AS title, NEW adCurrency AS 
Price, NEW adChar(4) AS pub_id) "
strShape = strShape & "RELATE pub_id TO pub_id) AS rstTitles"

Set objRs = New Recordset
objRs.Open strShape, objConn, adOpenStatic, adLockBatchOptimistic

For intCountA = 1 To 5
    objRs.AddNew
    objRs.Fields(0) = intCountA
    objRs.Fields(1) = intCountA
    objRs.Update
    For intCountB = 1 To 5
        If objRSChild Is Nothing Then
            Set objRSChild = objRs.Fields("rstTitles").Value
        End If
        objRSChild.AddNew
        objRSChild.Fields(0) = intCountB
        objRSChild.Fields(3) = intCountA
        objRSChild.Update
    Next
Next
'end of original code

I then bind the recordset to an Infragistics UltraGrid control and this 
works fine.

If I then add in a third level into the SHAPE statement (as shown below) 
and populate the recordset in a similar way, I get one record in 
the 'grandchild' level for every 'parent' and 'grandchild' combination
(ie. I get 25 records in every 'grandchild' recordset when I am only 
expecting 5)
I have tried APPENDing the pub_id field into the 'grandchild' level to 
ensure that every record is totally unique but this doesn't appear to make 
any difference.


'start of new code
strConn = "Provider=MSDataShape; Data Provider=none"
Set objConn = New ADODB.Connection
objConn.Open strConn

strShape = "SHAPE APPEND NEW adChar(4) AS pub_id, NEW adVarChar(40) AS 
pub_name, NEW adVarChar(20) AS city, "
strShape = strShape & "NEW adChar(2) AS State, NEW adVarChar(30) AS 
country, ((SHAPE APPEND NEW adVarChar(6) AS title_id, "
strShape = strShape & "NEW adVarChar(80) AS title, NEW adCurrency AS 
Price, NEW adChar(4) AS pub_id, "
strShape = strShape & "((SHAPE APPEND NEW adInteger AS PageID, NEW 
adVarChar(6) AS title_id) RELATE title_id TO title_id) AS rstPages) RELATE 
pub_id TO pub_id) AS rstTitles"

Set objRs = New Recordset
objRs.Open strShape, objConn, adOpenStatic, adLockBatchOptimistic

For intCountA = 1 To 5
    objRs.AddNew
    objRs.Fields(0) = intCountA
    objRs.Fields(1) = intCountA
    objRs.Update
    For intCountB = 1 To 5
        If objRSChild Is Nothing Then
            Set objRSChild = objRs.Fields("rstTitles").Value
        End If
        objRSChild.AddNew
        objRSChild.Fields(0) = intCountB
        objRSChild.Fields(3) = intCountA
        objRSChild.Update
        For intCountC = 1 To 5
            If objRSGChild Is Nothing Then
                Set objRSGChild = objRSChild.Fields("rstPages").Value
            End If
            objRSGChild.AddNew
            objRSGChild.Fields(0) = intCountC
            objRSGChild.Fields(1) = intCountB
            objRSGChild.Update
        Next
    Next
Next
'end of new code


I would be very grateful if anyone can tell me what I'm doing wrong
Thanks
Neil

  Return to Index