Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Right here goes I hope... I have a Friend sub I want to convert to a class? is there a way to do it? attached is the code incase there ahve to be some changes. I admit the code is not my own design, but have a use for ti as a class instead of a friend sub.

 

Treeviews and classes are new to me in VB.net as I'm still learning.

 

Friend Sub BindToTreeview(ByVal TableName As String, ByVal FieldName As String, ByVal tView As TreeView)

 

'Variables

Dim DbConn As ADODB.Connection

Dim DBPATH As String

 

DBPATH = AppPath & "Time.mdb"

 

'Connect To Database

Dim DbConnString As String

DbConnString = "Driver={Microsoft Access Driver (*.mdb)};" & _

"DBQ=" & DBPATH

 

'Open Database

DbConn = New ADODB.Connection

DbConn.ConnectionString = DbConnString

DbConn.Open()

 

'Create SQL

Dim SQL As String

SQL = "SELECT " & FieldName & " FROM " & TableName & ";"

 

'Create Recordset

Dim rSet As ADODB.Recordset

rSet = DbConn.Execute(SQL)

 

'Bind To Treeview

Dim tvItem As TreeNode

tvItem = New TreeNode

tvItem.Text = FieldName

 

While Not rSet.EOF

If rSet.Fields(0).ActualSize <> 0 Then tvItem.Nodes.Add(rSet.Fields(0).Value)

rSet.MoveNext()

End While

 

tView.Nodes.Add(tvItem)

 

'Close Database

DbConn.Close()

End Sub

 

Thanx a million

P.L.U.R - Peace, Love, Unity, Respect :P
Posted
why would I need to convert it to ADO.net? all I'm really wanting to do is create a reusable bind to tree function to bind a few treeviews in an app I'm writing... I'm still new to vb.net so still hazy on why and how to do things
P.L.U.R - Peace, Love, Unity, Respect :P

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...