TreeView Populated from DB (Error in V.Studio.Net)

P

Patrick.O.Ige

Hi Guys,
I have an application below that is treeview menu populated from the
database which works with asp.net webmatrix.But when i put it into code
behind in Visual Studio.Net it gives the errors

"TreeNode Not defined"
"name TreeeView1 not defined"
Can anybody tell me what 'm doing wrong?

Sub Page_load(Sender As Object, E As EventArgs)
'Connection to the DB(DB connection objects)
Dim strConn As String =
"server=(local);database=Northwind;integrated security=true;"
'Dim strConn As String =
"server=(local);database=pubs;trusted_connection=true;"

Dim objConn As New SqlConnection(strConn)

'Created a Dataset to fill in the Data
Dim objDS As New DataSet

Dim daSuppliers As New SqlDataAdapter("SELECT CompanyName,SupplierID
FROM Suppliers", objConn)
Dim daProducts As New SqlDataAdapter("SELECT ProductName, ProductID,
SupplierID FROM Products", objConn)

'Filled in the Data and close connections
'daSuppliers is the DataAdapter
daSuppliers.Fill(objDS, "dtSuppliers")
daProducts.Fill(objDS, "dtProducts")

'daSuppliers.Fill(objDS)
'daProducts.Fill(objDS)


objConn.Close()

'A relation is created here because the Dataset has more than one
Datatable (there must be a common field in both
' to define the Parent Child relationship. In this is the SupplierID
objDS.Relations.Add("SuppToProd", _
objDS.Tables("dtSuppliers").Columns("SupplierID"), _
objDS.Tables("dtProducts").Columns("SupplierID"))


'Created TreeView datatypes
Dim nodeSupp, nodeProd As TreeNode
Dim rowSupp, rowProd As DataRow


'Loop through the datasets and populate the TreeView
For Each rowSupp In objDS.Tables("dtSuppliers").Rows

nodeSupp = New TreeNode

nodeSupp.Text = rowSupp("CompanyName")

nodeSupp.ID = rowSupp("SupplierID")

TreeView1.Nodes.Add(nodeSupp)

'Loop through SuppToProd which is a Datatable
For Each rowProd In rowSupp.GetChildRows("SuppToProd")

nodeProd = New TreeNode

nodeProd.Text = rowProd("ProductName")

'nodeProd.Text = <a href ="">" & rowProd("ProductName")
&"</a>


'<a href=""offers.asp?catID=" & rsCat("ServID") & """>" &
rsCat("ServiceName") & "</a>

nodeProd.ID = rowProd("ProductID")

nodeSupp.Nodes.Add(nodeProd)

Next

Next



'cleaned up to save server resources

objDS.Dispose()

daSuppliers.Dispose()

daProducts.Dispose()

objConn.Close()

objConn.Dispose()
End sub
 

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

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,744
Latest member
CortneyMcK

Latest Threads

Top