C# - Treeview error popular with SQL database tables

Asked

Viewed 32 times

0

I’m in trouble and I need help.
I want to popular a treeview with data from an SQL database, but I have an error when putting the data through the code it duplicates everything.
My query:

select 
   MLSGn01.BarGroup as dep,
   MLSGn01.MenuDesc as n01, 
   MLSGn01.Id, 
   MLSGn02.MenuDesc as n02,
   MLSGn02.Id 
from dbo.[SAMECA - P_Q_$MenuListSamecaGest] as MLSGn01
left join dbo.[SAMECA - P_Q_$MenuListSamecaGest] as MLSGn02 on MLSGn01.Id = MLSGn02.ParentID 
where MLSGn01.ParentID = 0"

Code:

`           SqlCommand cmd = new SqlCommand(query, log.connNAV);
            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                TreeNode node = new TreeNode(dr["dep"].ToString());
                node.Nodes.Add(dr["n01"].ToString());
                node.Nodes.Add(dr["n02"].ToString());

                treeView_menus.Nodes.Add(node);
            } `

Error:
Where "Dep" = Groupsales
Where "N01" = Budget
Being "N02" = Budget Maintenance / Prices Cost

inserir a descrição da imagem aqui

Goal:

inserir a descrição da imagem aqui

  • what data is returned in the query?

  • In any case, my reply yesterday partly settles that. Remember to mark your response if it helped you, and if you have difficulties go to [tour] to see how the community works.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.