Self Referencing Result Not Clean

G

Guest

I am trying to load a table with a self relation, but can't seem to figure
out how to load only top-level parent rows at the top of the data hierarchy.
Instead, all rows are coming across to the top level of the hierarchy, as
well as their children (per the relation--this part is good). I found an
example elsewhere, but it wasn't exactly what I was hoping for. Can anyone
recommend how to accomplish getting a clean result?

Dim myDS As New Data.DataSet
Dim mySelect As String = Nothing

mySelect = "SELECT * FROM vwWOBuilds WHERE ID = " & ID & " ORDER BY
ID"

Dim myDA As New System.Data.SqlClient.SqlDataAdapter(mySelect,
myApp.Server.Provider2)
myDA.Fill(myDS)

Dim myR As New DataRelation("SelfReferencing",
myDS.Tables(0).Columns("ID"), myDS.Tables(0).Columns("ParentBuildID"), False)

myDS.Relations.Add(myR)

Return myDS.Tables(0)
 
R

Robbe Morris [C# MVP]

Wouldn't your query be by ParentID = null or ParentID = RecordID
depending on how you have your hierarchy set up?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top