C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




How to put data from Database to Treeview


Posted Date: 09 Sep 2008    Resource Type: Articles    Category: Web Applications

Posted By: kalaimanichozhan       Member Level: Gold
Rating:     Points: 10



In web application some times we have a need to retieve the data from the database and displayed through treeview. For that need following coding will be used.

        
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim con As New SqlConnection("server=VAXGEN-3;uid=sa;pwd=vgn;database=Northwind")

Dim ds, dst As New DataSet
Dim dt, dt1 As DataTable
Dim dr As SqlDataReader


Dim da As New SqlDataAdapter("select name from sysobjects where type='U'", con)
Dim count As Integer

con.Open()
da.Fill(ds, "table1")
con.Close()
dt = ds.Tables(0)
count = dt.Rows.Count


For Each drow As DataRow In dt.Rows
Dim name As String
name = drow(0).ToString()

Me.TreeView2.ShowCheckBoxes = TreeNodeTypes.Parent


Dim table As New TreeNode(name)
table.Value = name


rootnode.ChildNodes.Add(table)

Dim cmd As New SqlCommand("select * from " + name + "", con)


con.Open()
da.SelectCommand = cmd
da.Fill(dst, name)
dt = dst.Tables(name)

Dim ct As Integer = dt.Columns.Count()

For i As Integer = 0 To ct - 1
Dim column As New TreeNode(dt.Columns(i).ColumnName.ToString())
table.ChildNodes.Add(column)
Next
con.Close()

Next

End Sub







Attachments

  • Output For treeview (20831-9108-treeimg.doc)



  • Responses

    Author: sathya    10 Sep 2008Member Level: Silver   Points : 0
    Hi kalaimanichozhan

    This is very useful for me.Good!


    Feedbacks      
    Popular Tags   What are tags ?   Search Tags  
    Treeview from database  .  Treeview  .  Databind to treeview  .  

    Post Feedback


    This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
    You must Sign In to post a response.
    Next Resource: Disabling Mouse Rt Click and Function Keys on browser
    Previous Resource: Introduction to Basic HTML
    Return to Discussion Resource Index
    Post New Resource
    Category: Web Applications


    Post resources and earn money!
     
    Related Resources



    dotNet Slackers   BizTalk Adaptors    Web Design

    UK Conference calling Company

    Contact Us    Privacy Policy    Terms Of Use