473,406 Members | 2,259 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

how to do Binding with code

Hi all,
The beginner strikes back again (sorry)

this is the class I use for Nodes into a treeview,
I need to bind each field to a database..... How Can I do that ?

What I tried so far is to run a Dataview for operations, then set the
DataView rowfilter to "ser_id = " & ctype(nodes, service).id
then change directly into the Dataview.item(0) the columns I need to change.
Is there a more simple way to bind the "Service" nodes directly to the table
so I don't have to work with the Dataview ?

Any Example how to build a binding to a database with our own class would be
appreciated.

Thanks to you all,
Have a nice day !

Marc R.


Public Class service
Inherits treenodes

'Private Member

Private p_ID As Integer

Private p_Name As String

Private P_Active As Boolean

Public Property ID() As Integer

Get

Return p_ID

End Get

Set(ByVal Value As Integer)

p_ID = Value

End Set

End Property

Public Property Name() As String

Get

Return p_Name

End Get

Set(ByVal Value As String)

p_Name = Value

End Set

End Property

Public Property Active() As Boolean

Get

Return P_Active

End Get

Set(ByVal Value As Boolean)

P_Active = Value

End Set

End Property

End Class


Feb 8 '06 #1
3 994

"Marc R." <No****@NewgroupsONLY.com> wrote in message
news:eP**************@tk2msftngp13.phx.gbl...
Hi all,
The beginner strikes back again (sorry)

this is the class I use for Nodes into a treeview,
I need to bind each field to a database..... How Can I do that ?

What I tried so far is to run a Dataview for operations, then set the
DataView rowfilter to "ser_id = " & ctype(nodes, service).id
then change directly into the Dataview.item(0) the columns I need to
change. Is there a more simple way to bind the "Service" nodes directly to
the table so I don't have to work with the Dataview ?

Any Example how to build a binding to a database with our own class would
be appreciated. Actually, I would like to bind each service to 1 datarow
only

Thanks to you all,
Have a nice day !

Marc R.


Public Class service
Inherits treenodes

'Private Member

Private p_ID As Integer

Private p_Name As String

Private P_Active As Boolean

Public Property ID() As Integer

Get

Return p_ID

End Get

Set(ByVal Value As Integer)

p_ID = Value

End Set

End Property

Public Property Name() As String

Get

Return p_Name

End Get

Set(ByVal Value As String)

p_Name = Value

End Set

End Property

Public Property Active() As Boolean

Get

Return P_Active

End Get

Set(ByVal Value As Boolean)

P_Active = Value

End Set

End Property

End Class

Feb 8 '06 #2
"Marc R." <No****@NewgroupsONLY.com> wrote in message
news:eP**************@tk2msftngp13.phx.gbl...
Is there a more simple way to bind the "Service" nodes directly to the
table so I don't have to work with the Dataview ?


Certainly, but you just wind up with the code inside the Service class,
rather than anywhere else and you'll be starting to fight the battles of
encapsulation vs performance.

Some suggestions:

1) Leave things as they are, loading data into each Service object
from the DataView - OK, it's "messy", but it works.
At the very least, I recommend to code your own Constructor
so that you set all the properties in one go, as in

Public Class Service
. . .
Public Sub New(
ByVal id As Integer _
, ByVal name As String _
, ByVal active As Boolean _
)
' Load values into properties
p_ID = id
p_Name = name
p_Active = active

End Sub
.. . .

2) Keep the DataView (so your database access stays where it is),
and create each Service object based on, say, a row from the
DataView, something like

Public Class Service
Public Sub New( _
ByVal sourceData as DataViewRow _
)
' Load data from DataViewRow into properties
p_ID = sourceData.Item( "id" )
End Sub
.. . .

Both of the above are limited in that you're getting a /copy/ of the data
in each object. unless you move the database code itself into the Service
class, you can't feed changes [directly] back into the database, so ...

3) Transfer all the data access into the Service class as well.
You'd probably want to do much the same as in (2), but passing
in the database /connection/ instead of the already loaded DataView,
and probably the id of the Service to load.

Public Class Service
Public Sub New( _
ByVal id As Integer _
, ByVal connection As WhicheverConnectionYouUse _
)
' Save the connection, so we can use it do updates - maybe
p_Connection = connection

' Load data from DataViewRow into properties
p_ID = GoAndGetDataFromConnection( connection, id )

End Sub
.. . .

4) Or, because that'll be /horrendously/ slow cmpared to loading the
data from the DataView (because each Service object has to do its
own, /individual/ data retrieval), you might tackle it completely the
other way around ... Create a Shared method on the Service class
that takes a /TreeView/ as argument, finds all the Services (from the
Database), creates a Service object for each and adds these into the
TreeView. <whew>

Public Class Service
Public Shared Sub LoadTree( _
ByVal treeToLoad As TreeView _
, ByVal connection As WhicheverConnectionYouUse _
)
Dim dv As DataView = ... DataFromDatabase

For Each dr As DataRowView In dv
Dim node As Service _
= New Service( dr )

treeToLoad.Nodes.Add( node )
Next
End Sub
.. . .

(plus, of course, at least 101 others I /haven't/ thought of ... )

Personally, I think I'd be heading for option (2).

HTH,
Phill W.
Feb 8 '06 #3
the funny part I use suggestion #1 and 2 already this is the way I was
planning to go.
At lease now I know I'm on the good track

Thanks.
"Phill W." <p-***********@o-p-e-n.a-c.u-k> wrote in message
news:ds**********@yarrow.open.ac.uk...
"Marc R." <No****@NewgroupsONLY.com> wrote in message
news:eP**************@tk2msftngp13.phx.gbl...
Is there a more simple way to bind the "Service" nodes directly to the
table so I don't have to work with the Dataview ?


Certainly, but you just wind up with the code inside the Service class,
rather than anywhere else and you'll be starting to fight the battles of
encapsulation vs performance.

Some suggestions:

1) Leave things as they are, loading data into each Service object
from the DataView - OK, it's "messy", but it works.
At the very least, I recommend to code your own Constructor
so that you set all the properties in one go, as in

Public Class Service
. . .
Public Sub New(
ByVal id As Integer _
, ByVal name As String _
, ByVal active As Boolean _
)
' Load values into properties
p_ID = id
p_Name = name
p_Active = active

End Sub
. . .

2) Keep the DataView (so your database access stays where it is),
and create each Service object based on, say, a row from the
DataView, something like

Public Class Service
Public Sub New( _
ByVal sourceData as DataViewRow _
)
' Load data from DataViewRow into properties
p_ID = sourceData.Item( "id" )
End Sub
. . .

Both of the above are limited in that you're getting a /copy/ of the data
in each object. unless you move the database code itself into the Service
class, you can't feed changes [directly] back into the database, so ...

3) Transfer all the data access into the Service class as well.
You'd probably want to do much the same as in (2), but passing
in the database /connection/ instead of the already loaded DataView,
and probably the id of the Service to load.

Public Class Service
Public Sub New( _
ByVal id As Integer _
, ByVal connection As WhicheverConnectionYouUse _
)
' Save the connection, so we can use it do updates - maybe
p_Connection = connection

' Load data from DataViewRow into properties
p_ID = GoAndGetDataFromConnection( connection, id )

End Sub
. . .

4) Or, because that'll be /horrendously/ slow cmpared to loading the
data from the DataView (because each Service object has to do its
own, /individual/ data retrieval), you might tackle it completely the
other way around ... Create a Shared method on the Service class
that takes a /TreeView/ as argument, finds all the Services (from the
Database), creates a Service object for each and adds these into the
TreeView. <whew>

Public Class Service
Public Shared Sub LoadTree( _
ByVal treeToLoad As TreeView _
, ByVal connection As WhicheverConnectionYouUse _
)
Dim dv As DataView = ... DataFromDatabase

For Each dr As DataRowView In dv
Dim node As Service _
= New Service( dr )

treeToLoad.Nodes.Add( node )
Next
End Sub
. . .

(plus, of course, at least 101 others I /haven't/ thought of ... )

Personally, I think I'd be heading for option (2).

HTH,
Phill W.

Feb 14 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: JD Kronicz | last post by:
Hi .. I have an issue I have been beating my head against the wall on for some time. I am trying to use late binding for MS graph so that my end users don't have to worry about having the right...
14
by: Composer | last post by:
I've read many postings about the problem of Access.References.IsBroken and the consensus seems to be that late binding is the cure-all. I have a very complex Access application that needs...
9
by: Zlatko Matić | last post by:
I was reading about late binding, but I'm not completely sure what is to be done in order to adjust code to late binding... For example, I'm not sure if this is correct: early binding: Dim ws...
19
by: Simon Verona | last post by:
I'm not sure if I'm going down the correct route... I have a class which exposes a number of properties of an object (in this case the object represents a customer). Can I then use this...
0
by: Larry Serflaten | last post by:
I am not sure how many are aware of this sort of data binding, but as it is new to many (classic) VB developers I thought I would post this once just to let people know of its availablility. ...
30
by: lgbjr | last post by:
hi All, I've decided to use Options Strict ON in one of my apps and now I'm trying to fix a late binding issue. I have 5 integer arrays: dim IA1(500), IA2(500), IA3(500), IA4(500), IA5(500) as...
19
by: Larry Lard | last post by:
In the old days (VB3 era), there was a thing called the Data Control, and you could use it to databind controls on forms to datasources, and so (as the marketing speak goes), 'create database...
3
by: Simon Tamman | last post by:
I've come across an interesting bug. I have workarounds but i'd like to know the root of the problem. I've stripped it down into a short file and hope someone might have an idea about what's going...
3
ADezii
by: ADezii | last post by:
The process of verifying that an Object exists and that a specified Property or Method is valid is called Binding. There are two times when this verification process can take place: during compile...
7
by: Steve K | last post by:
First problem: I am specifying a format string for a Binding object like so: <code> Binding binding = new Binding("Text", item.EOBRemittance, "AmountAllowed", true, DataSourceUpdateMode.Never,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.