Click here to Skip to main content
15,896,726 members
Articles / Programming Languages / Visual Basic

Database Helper v 2.0.0

Rate me:
Please Sign up or sign in to vote.
4.68/5 (75 votes)
8 Jun 2010CPOL8 min read 209.6K   21.6K   270  
An open source code generation utility with some useful features to generate procedures,class for tables and .net code for procedures automatically.
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Windows.Forms;

/// <summary>
/// Summary description for TreeGenerator
/// </summary>
public class TreeGenerator
{
    //private SqlConnection dbCon;

    public TreeGenerator(string StoredProcedureName)
    {
        //
        // TODO: Add constructor logic here
        //
        //storedProcedureName = StoredProcedureName;

        //dbCon = new SqlConnection(ConfigurationManager.ConnectionStrings["DB_Connection"].ToString());
        //dbCon.Open();
    }


    public static void GenerateTreeView(TreeView Tree, DataSet ds)
    {
        /*
        OleDbConnection dbCon = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~/TreeView/Data/Tree.mdb"));
        dbCon.Open();

        OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM Links", dbCon);
        DataSet ds = new DataSet();
        adapter.Fill(ds);
         */

        ds.Relations.Add("NodeRelation", ds.Tables[0].Columns["ID"], ds.Tables[0].Columns["ParentID"]);

        foreach (DataRow dbRow in ds.Tables[0].Rows)
        {
            if (dbRow.IsNull("ParentID"))
            {
                TreeNode node = CreateNode(dbRow["Text"].ToString(), true, dbRow["ID"].ToString());
                Tree.Nodes.Add(node);
                RecursivelyPopulate(dbRow, node);
            }
        }
    }

    private static void RecursivelyPopulate(DataRow dbRow, TreeNode node)
    {
        foreach (DataRow childRow in dbRow.GetChildRows("NodeRelation"))
        {
            TreeNode childNode = CreateNode(childRow["Text"].ToString(), true, childRow["ID"].ToString());
            node.Nodes.Add(childNode);
            RecursivelyPopulate(childRow, childNode);
        }
    }

    private static TreeNode CreateNode(string text, bool expanded, string id)
    {
        TreeNode node = new TreeNode(text);
        node.ImageIndex = 0;
        return node;
    }

}

   

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Database Developer
Iran (Islamic Republic of) Iran (Islamic Republic of)
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions