Friend Sub to class convertion

absent

Regular
Joined
Sep 25, 2003
Messages
55
Location
UK
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
 
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
 
Back
Top