title: Windows Forms application that loads a tree from a database table, and displays it in a TreeView object?
body: <p>This is the Code I have so far, I am having problem with the loop, I don't get it.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Data.OleDb;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;
  
  namespace WindowsFormsApplication11_TreeView
  {
      public partial class Form1 : Form
      {
          OleDbConnection dbConn;
          public Form1()
          {
              InitializeComponent();
              string connStr = @"Provider=Microsoft.ACE.OLEDB.12.0; DataSource=PartsTree.accdb";
              try
              {
                  dbConn = new OleDbConnection(connStr);
                  dbConn.Open();
                  AddChildNodes(treeView1.Nodes, 0);
                  dbConn.Close();
                  dbConn.Dispose();
              }
              catch (OleDbException e)
              {
                  MessageBox.Show(e.Message, "Exception!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                  Application.Exit();
              }
          }
  
          private void AddChildNodes(TreeNodeCollection nodes, int parent)
          {
              string queryStr = "SELECT ID, parent_ID, description";
              queryStr += "FROM parts Where parent_ID";
              queryStr += (0 == parent ? "IS NULL;" : "=?");
              OleDbCommand dbCmd = dbConn.CreateCommand();
              dbCmd.CommandText = queryStr;
  
              if (0 != parent)
              {
                  OleDbParameter parameter = dbCmd.Parameters.Add("@InputParm", OleDbType.Integer);
                  parameter.Value = parent;
              }
  
              using (OleDbDataReader rdr = dbCmd.ExecuteReader())
              {
                  while (rdr.Read())
                  {
  
                  }
                  rdr.Close();
              }
          }
  
          private void Form1_Load(object sender, EventArgs e)
          {
  
          }
  
      }
  }
  </code></pre>