I try to create XtraDiagram (with DataTable) but this topic is related on DataTable construction. Exscuse me if i ask you this problem. This is recursion problem. My scope is populate DataTable with all member of hierarchical structure (like for example file system). In the last while i try to cycle for all children finded. In this section, i call recursive function for continue the analisys. The routine start ok and analisys until the last box. But after come back without analyze the other children… The sqldatareader lost his function? Because? Thanks very much anticipated.
Public Function CreateDiagram(connection As SqlConnection, IDdoc2 As Integer, IDdoc1 As Integer) As Integer
'creation XtraDiagram
Dim cmd As SqlCommand = New SqlCommand()
Dim dr As SqlDataReader
Dim strItemName As String = String.Empty
'creation item
dt.Rows.Add(IDdoc2, strItemName, IDdoc1, "")
'extract how many children there are
cmd.Connection = connection
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT IDdocumento_1 FROM tbRelazioniDocumenti WHERE
IDdocumento_2=" & IDdoc2
dr = cmd.ExecuteReader
If dr.HasRows Then
While dr.Read()
'for every children
Return CreateDiagram(connection, dr.Item("IDdocumento_1"), IDdoc2)
End While
Else
Return 0
End If
cmd.Dispose()
dr.Close()
End Function
Public Function CreateDiagram2(connection As SqlConnection, IDdoc2 As Integer, IDdoc1 As Integer) As Integer
Dim cmd As SqlCommand = New SqlCommand()
Dim dr As SqlDataReader
Dim strItemName As String = String.Empty
Dim arr() As Integer
ReDim arr(0)
'tento di estrapolare i figli
cmd.Connection = connection
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT IDdocumento_1 FROM tbRelazioniDocumenti WHERE IDdocumento_2=" & IDdoc2
dr = cmd.ExecuteReader
If dr.HasRows Then
While dr.Read()
ReDim Preserve arr(UBound(arr) + 1)
arr(UBound(arr)) = dr.Item("IDdocumento_1")
End While
Else
Return 0
End If
cmd.Dispose()
dr.Close()
Dim i As Integer
For i = 1 To UBound(arr)
Return CreateDiagram2(connection, arr(i), IDdoc2)
Next i
End Function